ggplot2: make the points on the line a darker color than the line color

后端 未结 1 800
难免孤独
难免孤独 2021-01-20 23:29

I would like to make each point on the graph a different color from the line. Here is sample data.

df <- structure(list(yrmonth = structure(c(17167, 17167, 17         


        
1条回答
  •  清酒与你
    2021-01-21 00:05

    You could use a filled point marker (shapes 21 through 25), which would allow you to set the fill colors for the points separately from the colors of the lines. In the code below, I use the same hues (the h argument to the hcl function) for the points and lines, but a lower luminance (the l argument to hcl) for the points so that they will be darker than the lines. I've also increased the line and point sizes to make it easier to see the difference.

    ggplot(df, aes(x=yrmonth,y=data)) + 
      geom_line(size=1, aes(colour=factor(index))) + 
      geom_point(size=3, aes(fill=factor(index)), shape=21, colour="#FFFFFF00") +
      scale_colour_manual(values=hcl(seq(15,375,length=4)[1:3], 100, 70)) +
      scale_fill_manual(values=hcl(seq(15,375,length=4)[1:3], 100, 40)) +
      theme_classic() +
      labs(colour="Index", fill="Index")
    

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