【发布时间】:2013-01-16 07:43:47
【问题描述】:
我有两个变量要在直方图中进行比较,如下图所示。对于直方图的每个 bin,都会显示两个变量的频率,以便于比较它们。
【问题讨论】:
-
这个问题的答案说明了另一种方法,它可能更适合高斯数据:stackoverflow.com/questions/3541713/…
标签: r plot histogram data-visualization
我有两个变量要在直方图中进行比较,如下图所示。对于直方图的每个 bin,都会显示两个变量的频率,以便于比较它们。
【问题讨论】:
标签: r plot histogram data-visualization
你可以使用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 参数。
【讨论】:
你可以像这样使用prop.table和barplot
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)
【讨论】: