Commit c3702076 authored by Jean-Marie Lepioufle's avatar Jean-Marie Lepioufle
Browse files

add plot not-NA indicator tineseries

parent 046f0598
......@@ -5,6 +5,7 @@ export(basic_info)
export(basic_ts)
export(plot_boxwhisk_ts)
export(plot_lmrd)
export(plot_na_ts)
export(plot_qq)
export(plot_qqRes)
export(plot_tbl_basic)
......
#' plot_na_ts
#' plot_na_ts
#' @param x object of class tbl_friendlyts
#' @param fromDate fromDate
#' @param toDate toDate
#' @param timeResolution timeResolution
#' @param tzone tzone
#' @param path path
#' @param name name
#' @param width_mm width_mm
#' @param height_mm height_mm
#' @param DESKTOP boolean
#' @keywords friendlyts
#' @export
#' @examples
#' \dontrun{
#' plot_na_ts()
#' }
plot_na_ts <- function(x,fromDate=NULL,toDate=NULL,timeResolution=NULL,tzone="UTC",path=tempdir(),name=NULL,width_mm=200,height_mm=200,DESKTOP=TRUE){
# sub-period
if (!is.null(fromDate) && !is.null(toDate) && !is.null(timeResolution)) {
tmp <- friendlyts::sub_period(tbl_fts=x,fromDate=fromDate,toDate=toDate,timeResolution=timeResolution,tzone=tzone)
} else tmp <- x
df <- friendlyts::dfts(tbl_fts=tmp,timeResolution=timeResolution,tzone=tzone)
df[["date"]] <- as.POSIXct(df[["date"]])
# cat("df \n")
# print(df)
target <- setdiff(names(df), "date")
tmp <- lapply(target,function(y) {
res <- rep(1,length(df[[y]]))
res[is.na(df[[y]])] <- NA
res <- data.frame(date=df[["date"]],notna=res,target=y,stringsAsFactors=FALSE)
return(res)
})
tmp <- do.call("rbind",tmp)
tmp <- data.frame(date=tmp[,"date"],notna=tmp[,"notna"]*as.integer(as.factor(tmp[,"target"])),target = as.factor(tmp[,"target"]))
# cat("tmp \n")
# print(head(tmp))
#start plot
if (!(DESKTOP)) {
if(is.null(name)) {
filename <- normalizePath(file.path(path,paste0("na_ts.tiff")),mustWork = FALSE)
} else filename <-normalizePath(file.path(path,paste0("na_ts_",name,".tiff")),mustWork = FALSE)
grDevices::tiff(filename = filename, width = width_mm, height = height_mm,
units = "mm", pointsize = 12,
compression = "lzw",
bg = "transparent", res = 300)
} else grDevices::dev.new()
# plot
p <- ggplot2::ggplot(tmp, ggplot2::aes(x=date,y=notna,colour=target)) +
ggplot2::geom_point() +
ggplot2::labs(x = "date",y = "") #+
#ggplot2::theme(axis.line.y=ggplot2::element_blank(),axis.text.y=ggplot2::element_blank())
print(p)
if (!(DESKTOP)) {
grDevices::dev.off()
return(filename)
} else {
return(TRUE)
}
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/plot_na_ts.R
\name{plot_na_ts}
\alias{plot_na_ts}
\title{plot_na_ts
plot_na_ts}
\usage{
plot_na_ts(x, fromDate = NULL, toDate = NULL, timeResolution = NULL,
tzone = "UTC", path = tempdir(), name = NULL, width_mm = 200,
height_mm = 200, DESKTOP = TRUE)
}
\arguments{
\item{x}{object of class tbl_friendlyts}
\item{fromDate}{fromDate}
\item{toDate}{toDate}
\item{timeResolution}{timeResolution}
\item{tzone}{tzone}
\item{path}{path}
\item{name}{name}
\item{width_mm}{width_mm}
\item{height_mm}{height_mm}
\item{DESKTOP}{boolean}
}
\description{
plot_na_ts
plot_na_ts
}
\examples{
\dontrun{
plot_na_ts()
}
}
\keyword{friendlyts}
......@@ -17,10 +17,17 @@ knitr::opts_chunk$set(collapse = T, comment = "#>")
### install
```R
library("devtools")
devtools::install_git("https://git.nilu.no/rdiagnosis/basicr.git")
devtools::install_git("https://git.nilu.no/rfriendlyr/friendlyr.git")
devtools::install_git("https://git.nilu.no/rfriendlyr/d.luft.oslyr.git")
devtools::install_git("https://git.nilu.no/rdiagnosis/basicr.git")
# remarks
# basicr requires ggplot2 version 3.1.1
remove.packages("ggplot2")
install.packages("https://cran.r-project.org/src/contrib/Archive/ggplot2/ggplot2_3.1.1.tar.gz", repo=NULL, type="source")
```
### Get the 'data.luftkval.oslo10' dataset with friendlyr.
......@@ -46,18 +53,26 @@ luft <- friendlyr::ts(service="d.luft.oslyr",
fromDate=fromDate,toDate=toDate,precision=timeResolution,timeResolution=timeResolution,
element_id=element_id,station_id=station_id)
# filter negatives values, used as NA
# filter values equal to -9900 used as NA
varnames <- setdiff(names(luft), friendlyts::get_name_date_col(precision))
library(dplyr)
library(tidyr)
tmp <- luft %>% select(names(luft)) %>%
gather(variable, value, -c(friendlyts::get_name_date_col(precision))) %>%
mutate(value = replace(value, value < 0, NA)) %>%
mutate(value = replace(value, value == -9900, NA)) %>%
spread(variable, value) %>% friendlyts::as_tbl_friendlyts(precision=precision,date_type="friendlyts")
```
### Missing values
```R
basicr::plot_na_ts(x=tmp,timeResolution=timeResolution,DESKTOP=TRUE)
```
### basics characteristics
```R
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment