I have a simple melted data frame with 5 variables that I am plotting in a multiple line graph in ggplot2. I posted my code below and I feel the answer to this question should be simple, yet I can't find the answer.
If I am plotting 5 lines together on the same chart, is there a way to make one of the lines (the mean in this case) bolder/larger than the others?
As you can see in the code at the bottom, I specified that the size of the lines as 2 which makes all 5 lines the size of 2. But I was hoping to have the Mean line (the line specified as black in the scale colour function) become larger than the other lines.
I attempted setting size to size = c(2,2,2,2,3)
but ggplot2 did not like that.
FiveLineGraph <- ggplot(data= df, aes(x= Date, y=Temperature, group= model, colour= model)) +
geom_line(size= 2) +
scale_colour_manual(values = c("red","blue", "green", "gold","black"))
Any ideas?
I appreciate your help in advance.
Thanks.
I've added data to make it a "reproducible example". This technique would work for the color of your lines also.
library("ggplot2")
set.seed(99)
df <- data.frame(x=c(1:5, 1:5, 1:5), y=rnorm(15, 10, 2),
group=c(rep("A", 5), rep("B", 5), rep("C", 5)),
stringsAsFactors=FALSE)
ggplot(df, aes(x=x, y=y, group=group, colour=group)) + geom_line(size=2)
df$mysize <- rep(2, nrow(df))
df$mysize[df$group=="B"] <- 4
ggplot(df, aes(x=x, y=y, colour=group, size=mysize)) + geom_line() +
scale_size(range = c(2, 4), guide="none")
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