我有两个变量要在直方图中进行比较,如下图所示。对于直方图的每个 bin,显示了两个变量的频率,这使得比较它们变得容易。
问问题
75504 次
2 回答
14
您可以使用该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
参数。
于 2013-02-01T02:44:59.577 回答
5
你可以使用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)
于 2013-02-01T02:38:37.217 回答