我的问题类似于
Normalizing y-axis in histograms in R ggplot to proportion
但我想补充一点。
通常,我在2x3构面设计中有6个直方图,我想分别对它们进行归一化。我将尝试在此处建立示例数据集以给出一个想法:
hvalues=c(3,1,3,2,2,5,1,1,12,1,4,3)
season=c("fall","fall","fall","fall","winter","winter","winter","winter","summer","summer","summer","summer")
year=c("year 1","year 1","year 2","year 2","year 1","year 1","year 2","year 2","year 1","year 1","year 2","year 2")
group=c("fall year 1","fall year 1","fall year 2","fall year 2","winter year 1","winter year 1","winter year 2","winter year 2","summer year 1","summer year 1","summer year 2","summer year 2")
all=data.frame(hvalues,season,year)
使用
ggplot(all, aes(x=hvalues,group=group)) +
geom_histogram(aes(y=..count../sum(..count..))) +
facet_grid(season ~ year)
给出总体比例(即合并所有方面)。我希望将每个组构面标准化为1。hvalue在我的实际数据中不是整数-它们是数字。
我是使用R的新手,非常感谢您的帮助。提前致谢!
最佳答案
解决方案是:
ggplot(all, aes(x=hvalues)) +
facet_grid(season ~ year,drop=T) +
geom_histogram(aes(y=(..count..)/tapply(..count..,..PANEL..,sum)[..PANEL..]))
我从这个question偷了这个
我觉得您的问题可能是那个问题的重复。
关于r - 分别在ggplot2中标准化多面直方图,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16339204/