【问题标题】:Histogram of two variables in RR中两个变量的直方图
【发布时间】:2013-01-16 07:43:47
【问题描述】:

我有两个变量要在直方图中进行比较,如下图所示。对于直方图的每个 bin,都会显示两个变量的频率,以便于比较它们。

【问题讨论】:

标签: r plot histogram data-visualization


【解决方案1】:

你可以使用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)

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

【讨论】:

  • 我建议使用 col=rgb(0,0,1,0.5) 和 col=rgb(1,0,0,0.5) 这样颜色是透明的,重叠部分更清晰可见。跨度>
【解决方案2】:

你可以像这样使用prop.tablebarplot

somkes <- sample(c('Y','N'),10,replace=T)
amount <- sample (c(1,2,3),10,replace=T)
barplot(prop.table(table(somkes,amount)),beside=T)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多