How to change x-axis tick label names, order and boxplot colour using R ggplot?

后端 未结 2 1037
无人及你
无人及你 2020-12-04 23:05

I have a folder containing csv files, each with two columns of data e.g.:

0,red
15.657,red
0,red
0,red
4.429,red
687.172,green
136.758,green
15.189,red
0.15         


        
2条回答
  •  醉梦人生
    2020-12-04 23:05

    Yes, you can do this. Use scale_color_manual, scale_fill_manual and scale_x_discrete as follows:

    # specify colors and order 
    colorder <- c( "green", "orange", "red", "blue") 
    bplot<-ggplot(boxplots, aes(Lineage, RPKM)) + 
      geom_boxplot(aes(fill=factor(Lineage))) + 
      geom_point(aes(colour=factor(Lineage))) + 
      scale_color_manual(breaks=colorder, # color scale (for points)
                         limits=colorder, 
                         values=colorder) +
      scale_fill_manual(breaks=colorder,  # fill scale (for boxes)
                        limits=colorder, 
                        values=colorder) +
      scale_x_discrete(limits=colorder)   # order of x-axis
    

提交回复
热议问题