Commit 417e1f3b authored by Jean-Marie Lepioufle's avatar Jean-Marie Lepioufle

first

parents
Package: plotfts
Type: Package
Version: 0.0.1
Authors@R: c(person("Jean-Marie", "Lepioufle", , "jml@nilu.no", role=c("aut","cre")))
Title: plotfts
Description: Simple charts with timeserie datasets.
Depends:
R (>= 3.2.0)
Imports:
friendlyts,
utils,
grDevices,
dplyr,
timemanip,
ggplot2,
tidyr
Remotes: git::https://git.nilu.no/rspacetimemanip/timemanip.git
License: GPL-3
Encoding: UTF-8
LazyData: false
RoxygenNote: 6.1.1
# Generated by roxygen2: do not edit by hand
export(plot_tbl_friendlyts)
export(sub_period)
importFrom(dplyr,"%>%")
importFrom(dplyr,arrange)
importFrom(dplyr,bind_cols)
importFrom(dplyr,filter)
importFrom(dplyr,filter_)
importFrom(dplyr,group_by)
importFrom(dplyr,group_by_)
importFrom(dplyr,mutate)
importFrom(dplyr,mutate_)
importFrom(dplyr,select)
importFrom(dplyr,select_)
importFrom(dplyr,transmute)
importFrom(dplyr,transmute_)
#' plot_friendlyts
#' plot_friendlyts
#' @param x object of class tbl_friendlyts
#' @param target target character
#' @param fromDate fromDate
#' @param toDate toDate
#' @param timeResolution timeResolution
#' @param tzone tzone
#' @param name name
#' @param width_mm width_mm
#' @param height_mm height_mm
#' @param y_name name on the y-axis
#' @param DESKTOP boolean
#' @keywords plotfts
#' @export
#' @examples
#' \dontrun{
#' plot_friendlyts()
#' }
plot_tbl_friendlyts <- function(x,target,fromDate=NULL,toDate=NULL,timeResolution=NULL,tzone="UTC",name=NULL,width_mm=200,height_mm=200,y_name="Y-axis",DESKTOP=FALSE){
nb_target <- length(target)
if (nb_target>0) {
# sub-period
if (!is.null(fromDate) && !is.null(toDate) && !is.null(timeResolution)) {
tmp <- sub_period(tbl_fts=x,fromDate=fromDate,toDate=toDate,timeResolution=timeResolution,tzone=tzone)
} else tmp <- x
tmp <- friendlyts::dfts(tbl_fts=tmp,timeResolution=timeResolution,tzone=tzone)
tmp <- as.data.frame(dplyr::select(tmp,c("date",target)))
# gather
df <- tmp %>% tidyr::gather("variable", "value", -"date")
#start plot
if (!(DESKTOP)) {
filename <- friendlyts::file_friendlyts(name=name,format= "tiff")
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(df, ggplot2::aes(date)) +
ggplot2::geom_line(ggplot2::aes(y = value, colour = variable)) +
ggplot2::labs(x = "date",y = y_name)
print(p)
if (!(DESKTOP)) {
grDevices::dev.off()
return(filename)
} else {
return(TRUE)
}
} else stop("no target")
}
#' @importFrom dplyr %>% bind_cols select select_ filter filter_ mutate mutate_ transmute transmute_ group_by group_by_ arrange
NULL
#' sub_period
#' sub_period
#' @param tbl_fts tbl friendlyts
#' @param fromDate fromDate
#' @param toDate toDate
#' @param timeResolution timeResolution
#' @param tzone tzone
#' @keywords plotfts
#' @export
#' @examples
#' \dontrun{
#' sub_period()
#' }
sub_period <- function(tbl_fts,fromDate,toDate,timeResolution,tzone="UTC"){
tmp <- friendlyts::dfts(tbl_fts=tbl_fts,timeResolution=timeResolution,tzone=tzone)
from = timemanip::YYYYmmddHHMMSS2_chr(as.character(fromDate),tzone=tzone)
to = timemanip::YYYYmmddHHMMSS2_chr(as.character(toDate),tzone=tzone)
indice <- which((tmp$date >= from) & (tmp$date <= to))
if (!is.null(indice)) {
res <- friendlyts::as_tbl_friendlyts(df=tmp[indice,],precision=timeResolution,date_col="date",date_type="posixlt",CHECKNAS=FALSE)
} else stop("indice is NULL")
return(res)
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/plot.R
\name{plot_tbl_friendlyts}
\alias{plot_tbl_friendlyts}
\title{plot_friendlyts
plot_friendlyts}
\usage{
plot_tbl_friendlyts(x, target, fromDate = NULL, toDate = NULL,
timeResolution = NULL, tzone = "UTC", name = NULL,
width_mm = 200, height_mm = 200, y_name = "Y-axis",
DESKTOP = FALSE)
}
\arguments{
\item{x}{object of class tbl_friendlyts}
\item{target}{target character}
\item{fromDate}{fromDate}
\item{toDate}{toDate}
\item{timeResolution}{timeResolution}
\item{tzone}{tzone}
\item{name}{name}
\item{width_mm}{width_mm}
\item{height_mm}{height_mm}
\item{y_name}{name on the y-axis}
\item{DESKTOP}{boolean}
}
\description{
plot_friendlyts
plot_friendlyts
}
\examples{
\dontrun{
plot_friendlyts()
}
}
\keyword{plotfts}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/utils.R
\name{sub_period}
\alias{sub_period}
\title{sub_period
sub_period}
\usage{
sub_period(tbl_fts, fromDate, toDate, timeResolution, tzone = "UTC")
}
\arguments{
\item{tbl_fts}{tbl friendlyts}
\item{fromDate}{fromDate}
\item{toDate}{toDate}
\item{timeResolution}{timeResolution}
\item{tzone}{tzone}
}
\description{
sub_period
sub_period
}
\examples{
\dontrun{
sub_period()
}
}
\keyword{plotfts}
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