【问题标题】:How to get boxplots using ggplot to overlap instead of faceting如何使用ggplot重叠而不是分面来获取箱线图
【发布时间】:2014-03-16 20:10:50
【问题描述】:

我是 ggplot 的新手,并且使用 ggplot 来显示我的数据对应于不同类型的箱线图。有四种类型。我发现我可以使用 facet_wrap 生成四个不同的图表。

ggplot(o.xp.sample, aes(power, reduction, fill=interaction(type,power), dodge=type)) +
   stat_boxplot(geom ='errorbar')+
   geom_boxplot() + 
   facet_wrap(~type)

我的问题是,我想将所有四个图表组合成一个图表,以便每种类型都有不同的颜色(并且稍微透明以显示其他图表)。这可能吗?

这是https://gist.github.com/anonymous/9589729的数据

【问题讨论】:

  • 您能提供一些数据吗?
  • 您的图表包含太多信息,我认为在一张图表上呈现所有内容并不是一个好主意。可视化统计数据应该尽可能简单,当你看到它时你就知道了一切。尽管如此,提供示例数据将不胜感激。您的数据中有多少次互动?
  • 我正在尝试添加数据

标签: r ggplot2 boxplot


【解决方案1】:

试试这个:

library(ggplot2)

o.xp.sample = read.csv("C:\\...\\data.csv",sep=",")

ggplot(o.xp.sample, aes(factor(power), reduction, fill=interaction(type,power), dodge=type)) +
  stat_boxplot(geom ='errorbar') +
  geom_boxplot() +
  theme_bw() + 
  guides(fill = guide_legend(ncol = 3)) #added line as suggested by Paulo Cardoso

【讨论】:

  • 您可能需要添加guides(fill = guide_legend(ncol = 3)) 以便于阅读。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多