ggplot: boxplot sort

十年热恋 提交于 2021-02-05 09:36:22

问题


How do I sort a boxplot in ggplot?

Here's what I'm trying to plot:

qplot(  row.names(pcaDF),pcaDF[,1],data=pcaDF,geom="boxplot") + coord_flip() 

and here's the structure of pcaDF

> str(pcaDF)
'data.frame':   108 obs. of  1 variable:
 $ sort(plotdata[, 1], decreasing = F): num  -5.89 -5.52 -4.66 -4.54 -3.92 ...

回答1:


Sorting in ggplot is regulated by the levels in the factors. To control the sorting of factor: A in df:

df$A = factor(df$A , level = sort(unique(df$A)) )



回答2:


This question is answered here: ggplot: how to specify vertical order of multiple boxplots?

Others finding this question and wanting to reorder (sort) other data with ggplot may find the following post useful. How to order breaks with ggplot / geom_bar

If other searchers still are lost trying using the keyword "order" in place of "sort" as this seems more fruitful from experience. :-)



来源:https://stackoverflow.com/questions/4037700/ggplot-boxplot-sort

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!