I can plot each series in a different colour in ggplot2 by doing something like this ...
colours <- c('red', 'blue')
p <- ggplot(data=m, mapping=aes_string(x='Date', y='value'))
p <- p + geom_line(mapping=aes_string(group='variable', colour='variable'), size=0.8)
p <- p + scale_colour_manual(values=colours)
Is there something comparable I can do to set different line widths for each series? (Ie. I want to use a thick red line to plot the trend and a thin blue line to plot the seasonally adjusted series.)
To change line width, just add argument size=2 to geom_line().
To set plot line width/thickness in R, call plot() function and along with the data to be plot, pass required thickness/line-width value for the “lwd” parameter.
Note that, line types can be also specified using numbers : 0, 1, 2, 3, 4, 5, 6. 0 is for “blank”, 1 is for “solid”, 2 is for “dashed”, ….
I would just add a new numeric variable to your data frame
##You will need to change this to something more appropriate
##Something like:
##m$size = as.numeric(m$variable == "seasonal")
m$size = rep(c(0, 1), each=10)
then add a size aesthetic to your plot command:
p = p + geom_line(aes(group=variable, colour=variable, size=size))
##Set the size scale
p + scale_size(range=c(0.1, 2), guide=FALSE)
Notice that I've added guide=FALSE
to avoid the size legend being displayed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With