R中两个变量的直方图
我有两个变量,我想在下面的直方图中进行比较。对于柱状图的每个箱子,显示了两个变量的频率,这使得比较它们变得容易R中两个变量的直方图,r,plot,histogram,data-visualization,R,Plot,Histogram,Data Visualization,我有两个变量,我想在下面的直方图中进行比较。对于柱状图的每个箱子,显示了两个变量的频率,这使得比较它们变得容易 您可以像这样使用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) somkes您可以使用add参数添加到hist(请参
您可以像这样使用
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)
somkes您可以使用add
参数添加到hist
(请参见?hist
,?plot.histogram
):
为了了解add
参数,我注意到在?hist
中,..
参数表示这些是传递给plot.histogram
的参数,add
记录在plot.histogram
中。或者,?hist
底部的一个例子使用了add
参数。这个问题的答案说明了另一种方法,它可能更适合高斯数据:我建议使用col=rgb(0,0,1,0.5)和col=rgb(1,0,0,0.5),这样颜色是透明的,重叠更明显。
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)