r - R中两个变量的直方图

标签 r plot histogram data-visualization

我有两个变量想要在直方图中进行比较,如下所示。对于直方图的每个箱,都会显示两个变量的频率,这使得比较它们变得很容易。

enter image description here

最佳答案

您可以使用add参数到hist(参见?hist?plot.histogram):

hist(rnorm(1000, mean=0.2, sd=0.1), col='blue', xlim=c(0, 1))
hist(rnorm(1000, mean=0.8, sd=0.1), col='red', add=T)

enter image description here

为了了解 add 参数,我注意到在 ?hist... 参数表示这些是传递给 plot.histogramadd 记录在 ?plot.histogram 中。或者,?hist 底部的示例之一使用 add 参数。

关于r - R中两个变量的直方图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14638788/

相关文章:

R 中的正则表达式在其他地方不起作用

r - 对于大整数 id 数字,使用 integer64、数字或字符哪个更好?

python - 使用 matplotlib 直方图模块时,为什么我会得到不同的 len(bins) 和 numb_bins 值?

python - Python 中数组的 2D 和 3D 散点直方图

R - 下载网站,包括所有 .css、.js、图片等

r - 从另一个 tabpanel 激活 tabpanel

python - 定性热图图 python

r - 组合ggplot和基础图形时,使面板具有相同的边距

python - 在 python 3.6 中绘制颜色条图例很困难

r - 使用 qplot 更改直方图的轮廓和填充颜色