When creating a multiple line plot in ggplot2, how do you make one line thicker than the others?

后端 未结 1 1738
终归单人心
终归单人心 2021-01-06 08:43

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 shou

相关标签:
1条回答
  • 2021-01-06 09:23

    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")
    

    0 讨论(0)
提交回复
热议问题