【问题标题】:ggplot: boxplot sortggplot:箱线图排序
【发布时间】:2010-10-27 21:00:45
【问题描述】:

如何在 ggplot 中对箱线图进行排序?

这是我要绘制的内容:

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

这是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 ...

【问题讨论】:

  • 没有可复现的例子很难回答,但简而言之,创建一个数据框,然后使用重新排序来更改行名的顺序。

标签: r ggplot2


【解决方案1】:

ggplot 中的排序由因子中的水平调节。控制因子的排序:df中的A:

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

【讨论】:

    【解决方案2】:

    这个问题在这里得到解答: ggplot: how to specify vertical order of multiple boxplots?

    其他发现此问题并希望使用 ggplot 重新排序(排序)其他数据的人可能会发现以下帖子很有用。 How to order breaks with ggplot / geom_bar

    如果其他搜索者仍然无法尝试使用关键字“order”代替“sort”,因为从经验来看,这似乎更有成效。 :-)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-11-10
      • 1970-01-01
      • 1970-01-01
      • 2011-05-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多