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

前端 未结 2 1635
南旧
南旧 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: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()
    

提交回复
热议问题