ggplot specific thick line

2019-02-17 11:06发布

问题:

How would one be able to plot one line thicker than the other. I tried using the geom_line(size=X) but then this increases the thickness of both lines. Let say I would like to increase the thickness of the first column, how would one be able to approach this?

a <- (cbind(rnorm(100),rnorm(100)))  #nav[,1:10]
sa <- stack(as.data.frame(a))
sa$x <- rep(seq_len(nrow(a)), ncol(a))
require("ggplot2") 
p<-qplot(x, values, data = sa, group = ind, colour = ind, geom = "line")
p + theme(legend.position = "none")+ylab("Millions")+xlab("Age")+
geom_line( size = 1.5)

回答1:

You need to map line thickness to the variable:

p + geom_line(aes(size = ind))

To control the thickness use scale_size_manual():

p + geom_line(aes(size = ind)) +
  scale_size_manual(values = c(0.1, 1))