How can I use different color palettes for different layers in ggplot2?

前端 未结 2 1631
南旧
南旧 2020-12-19 04:52

Is it possible to plot two sets of data on the same plot, but use different color palettes for each set?

testdf <- data.frame( x = rnorm(100), 
                   


        
相关标签:
2条回答
  • 2020-12-19 05:39

    If you translate the "blues" and "reds" to varying transparency, then it is not against ggplot's philosophy. So, using Thierry's Moltenversion of the data set:

    ggplot(Molten, aes(x, value, colour = variable, alpha = yc)) + geom_point()
    

    Should do the trick.

    0 讨论(0)
  • 2020-12-19 05:43

    That's not possible with ggplot2. I think it against the philosophy of ggplot2 because it complicates the interpreatation of the plot.

    Another option is to use different shapes to separate the points.

    testdf <- data.frame( x = rnorm(100), 
                          y1 = rnorm(100, mean = 0, sd = 1), 
                          y2 = rnorm(100, mean = 10, sd = 1),
                          yc = rnorm(100, mean = 0, sd = 3))
    Molten <- melt(testdf, id.vars = c("x", "yc"))
    ggplot(Molten, aes(x, value, colour = yc, shape = variable)) + geom_point()
    
    0 讨论(0)
提交回复
热议问题