change color for two geom_point() in ggplot2

后端 未结 2 1549
别跟我提以往
别跟我提以往 2020-12-31 06:59

Sample dataset:

library(ggplot2)    
df = read.table(text = 
              \"id      year    value1  value2 value3
            1           2000    1   2000           


        
2条回答
  •  灰色年华
    2020-12-31 07:30

    Is this what you are looking for?

    ggplot(df, aes(y=id)) +
      geom_point(aes(x=year, color=value1), size=4) +
      geom_point(aes(x=value3, colour ='value3'), size=3) +
      geom_point(aes(x=value2, colour ='value2'), size=5) +
      scale_colour_manual(name="",  
                          values = c("1"="yellow", "2"="orange", "3"="red",
                                     "value3"="grey", "value2"="black"))
    

    enter image description here

    Basically, just putting all possible colour labels in a single list.

提交回复
热议问题