Skip to content

Commit

Permalink
Merge pull request robjhyndman#319 from mitchelloharawild/gglagplot
Browse files Browse the repository at this point in the history
Added points to gglagplot() when do.lines=FALSE
  • Loading branch information
robjhyndman committed May 13, 2016
2 parents bdcd616 + f263e33 commit 4300a17
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
34 changes: 18 additions & 16 deletions R/ggplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ ggtsdisplay <- function(x, plot.type=c("partial","scatter","spectrum"),
}
}

gglagplot <- function(x, lags = 1, set.lags = 1:lags, diag=TRUE, diag.col="gray", do.lines = TRUE, colourlines = TRUE, labels = !do.lines, seasonal = TRUE, ...){
gglagplot <- function(x, lags = 1, set.lags = 1:lags, diag=TRUE, diag.col="gray", do.lines = TRUE, colour = TRUE, labels = FALSE, seasonal = TRUE, ...){
if (requireNamespace("ggplot2")){
if(frequency(x)>1){
linecol = cycle(x)
Expand Down Expand Up @@ -658,23 +658,25 @@ gglagplot <- function(x, lags = 1, set.lags = 1:lags, diag=TRUE, diag.col="gray"
p <- p + ggplot2::geom_abline(colour=diag.col, linetype="dashed")
}

if(do.lines){
if(labels){
linesize = 0.25
}
else{
linesize = 0.5
}
if(colourlines){
p <- p + ggplot2::geom_path(ggplot2::aes_(colour=~freqcur), size=linesize)
}
else{
p <- p + ggplot2::geom_path(size=linesize)
}
if(labels){
linesize = 0.25
}
else{
linesize = 0.5
}
plottype <- if(do.lines){
ggplot2::geom_path
}
else{
ggplot2::geom_point
}
if(colour){
p <- p + plottype(ggplot2::aes_(colour=~freqcur), size=linesize)
}
else{
colourlines <- FALSE
p <- p + plottype(size=linesize)
}

if(labels){
p <- p + ggplot2::geom_text(ggplot2::aes_(label=~lagnum))
}
Expand All @@ -692,7 +694,7 @@ gglagplot <- function(x, lags = 1, set.lags = 1:lags, diag=TRUE, diag.col="gray"
p <- p + ggplot2::facet_wrap(~lag, labeller = function(labels) lapply(labels, function(x) paste0("lag ",as.character(x))))
}
p <- p + ggplot2::theme(aspect.ratio=1)
if(colourlines){
if(colour){
p <- p + ggplot2::guides(colour = ggplot2::guide_colourbar(title=ifelse(seasonal, "season", "time")))
}

Expand Down
8 changes: 4 additions & 4 deletions man/gglagplot.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
\alias{gglagchull}
\title{Time series lag ggplots}
\usage{gglagplot(x, lags = 1, set.lags = 1:lags, diag=TRUE,
diag.col="gray", do.lines = TRUE, colourlines = TRUE,
labels = !do.lines, seasonal = TRUE, ...)
diag.col="gray", do.lines = TRUE, colour = TRUE,
labels = FALSE, seasonal = TRUE, ...)
gglagchull(x, lags = 1, set.lags = 1:lags, diag=TRUE,
diag.col="gray", ...)
}
Expand All @@ -14,8 +14,8 @@ gglagchull(x, lags = 1, set.lags = 1:lags, diag=TRUE,
\item{set.lags}{vector of positive integers specifying which lags to use.}
\item{diag}{logical indicating if the x=y diagonal should be drawn.}
\item{diag.col}{color to be used for the diagonal if(diag).}
\item{do.lines}{logical indicating if lines should be drawn.}
\item{colourlines}{logical indicating if lines should be coloured.}
\item{do.lines}{if TRUE, lines will be drawn, otherwise points will be drawn.}
\item{colour}{logical indicating if lines should be coloured.}
\item{labels}{logical indicating if labels should be used.}
\item{seasonal}{Should the line colour be based on seasonal characteristics (TRUE), or sequential (FALSE).}
\item{\dots}{Not used (for consistency with lag.plot)}
Expand Down

0 comments on commit 4300a17

Please sign in to comment.