ggplot2 change colours how

后端 未结 1 1432
别那么骄傲
别那么骄傲 2020-12-21 17:43

I want to do a ggplot2 scatter plot

    scores <- data.frame( SampleID = rep(LETTERS[1:3], 5), PC1 = rnorm(15), PC2 = rnorm(15) )
library( ggplot2 )
ggpl         


        
1条回答
  •  北海茫月
    2020-12-21 18:03

    scale_color_manual let's you pick the colors used.

    ggplot( scores, aes( x = PC1, y = PC2, colour = SampleID ) ) +
        geom_point() +
        scale_color_manual(values = c("red", "black", "dodgerblue2"))
    

    The cyl in the example refers to the cyl column of the mtcars dataset used in the example. If you would rather use shapes then colors, don't use the colour aesthetic, use the shape aesthetic instead.

    ggplot( scores, aes( x = PC1, y = PC2, shape = SampleID ) ) +
        geom_point()
    

    If you want to choose shapes (using usual R pch codes), then use scale_shape_manual.

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