Using a pre-defined color palette in ggplot

后端 未结 4 1667
别那么骄傲
别那么骄傲 2020-11-27 04:14

Does anyone know how to use a pre-defined color palette in ggplot?

I have a vector of colors I would like to use:

rhg_cols <- c(\"#771C19\", \"#AA         


        
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-27 04:27

    First add, the colours to your data set:

    mydata$col <- rhg_cols
    

    Then map colour to that column and use scale_colour_identity

    ggplot(mydata, aes(factor(phone_partner_products, colour = col))) + 
      geom_bar() + 
      scale_colour_identity()
    

提交回复
热议问题