我可以通过做这样的事情在ggplot2中以不同的颜色绘制每个系列...
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)
Run Code Online (Sandbox Code Playgroud)
我能为每个系列设置不同的线宽吗?(即我想使用粗红线绘制趋势,使用细蓝线绘制经季节性调整的系列.)
csg*_*pie 12
我只想在数据框中添加一个新的数字变量
##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)
Run Code Online (Sandbox Code Playgroud)
然后为plot命令添加尺寸美学:
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)
Run Code Online (Sandbox Code Playgroud)
请注意,我已添加guide=FALSE以避免显示大小图例.
小智 7
你可以这样做:
x <- 1:10
y1 <- x
y2 <- 1.5*x
df <- data.frame(x=rep(x, 2), y=c(y1, y2), id=as.factor(rep(1:2, each=10)))
ggplot(df) + geom_line(aes(x=x,y=y,group=id, colour=id, size=id)) +
scale_size_manual(values=c(1,4))
Run Code Online (Sandbox Code Playgroud)