Does anyone know how to change the color (or width or type) of the mean line in monthplot() or ggmonthplot()
Here is a quick example using both functions
myobs <- c( 147, 123, 131, 172, 166, 172, 180, 135, 208, 133, 134, 156,
181, 178, 150, 186, 189, 165, 164, 146, 213, 144, 164, 129,
178, 163, 186, 180, 149, 190, 200, 158, 201, 112, 100, 129,
157, 101, 133, 100, 117, 136, 129, 101, 167, 124, 113, 137,
148, 132, 141, 160, 148, 157, 156, 158, 204, 143, 168)
tsmyobs <- ts(myobs,start=c(2017,7), frequency=12)
monthplot(tsmyobs)
and
require(ggplot2)
require(fpp)
ggmonthplot(tsmyobs)
With monthplot() I get thin normal black lines for the subseries lines and thin normal black lines for the mean lines.
With ggmonthplot() I get thin normal black lines for the subseries lines and thin normal blue lines for the mean lines.
Ultimately I would like some control over the colors, weight, and type of both the subseries lines and the mean lines so I can contrast them visually a little better but at this point I would be happy just changing the color of the mean. I can not seem to find any controls for line color or line width or line type in either monthplot or ggmonthplot.
CodePudding user response:
There seem to be very limited customization options for ggmonthplot
, but it produces a ggplot object, so it is possible to modify it after creation.
For example, if you store your initial plot:
p <- ggmonthplot(tsmyobs)
p
You can change it to whatever size and color you want like this:
p$layers[[1]] <- geom_line(color = "red", size = 2)
p
You could even map seasons to the color aesthetic:
p$layers[[1]] <- geom_line(aes(color = factor(season)), size = 2)
p
You can even add scales and theme elements afterwards:
p
scale_color_viridis_d()
theme_bw(base_size = 16)
theme(legend.position = "none")