繁体   English   中英

如何绘制两个因素的多个直方图

[英]How to plot multiple histograms for two factors

我有一个像这样的data.frame(简化了,实际上每个参数有更多的值):

   params        value status
1    par1 9.214378e-01   good
...
5    par1 3.907796e+03   good
6    par1 1.440000e-01   bad
...
13   par1 5.343397e+01   bad
14   par2 3.430469e-03   good
...
18   par2 5.722368e-01   good
19   par2 3.764936e-03   bad
...
26   par2 1.291550e-01   bad
27   par3 4.750810e-01   good

带有20个参数的值,两个因素分别为“好” /“坏”。 我想将其绘制成表格形式的一组图表,在其中我可以看到“好”与“坏”的区别,每个参数有两个重叠的直方图。 每个参数都处于其特征间隔内。

我已经尝试过ggplot

p1 <- ggplot(data = DF) +
  geom_histogram(aes(x=value, color=status)) +
  facet_wrap(~params)

但这不起作用-条形图相互堆叠 在此处输入图片说明

使用position = 'dodge' ,否则条形图将被堆叠。

我想您正在寻找:

ggplot(data = data, aes(x=value, fill=status)) +
           geom_histogram(position = 'dodge') +
           facet_wrap(~params)

请让您的问题更具体,即不是2个因素,而是2个因素。

我认为我找到了解决方案,其中包括scales = "free"

p1 <- ggplot(data = DF) +
  geom_histogram(aes(x=value, fill=as.factor(status))) +
  facet_wrap(~params,scales = "free")

现在,该图看起来只有10个参数, 在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM