带有facet_wrap和单个stat_density的ggplot stat_density不匹配

时间:2016-08-26 07:57:11

标签: r graph ggplot2 facet-wrap

我有一个包含3个扇区wacc数据的df。当我绘制一个扇区的密度时,我得到了真实的对象。能源部门的密度图:

energy sector wacc density

但是当我使用facet_wrap时,密度函数是完全错误的,因为我得到以下图表:

density plot with facet wrap

使用facet_wrap时如何获得真实的密度图?

以下是代码:

 wacc <- c(0.05,0.05,0.07,0.05,0.06,0.04,0.04,0.03,0.04,0.04,0.04,0.04,0.04,0.03,0.03,0.04,0.04,0.04,0.04,0.04,0.05,0.05,0.05,0.04,0.05,0.05,0.04,0.05,0.04,0.04,0.06,0.04,0.04,0.1,0.1,0.1,0.07,0.08,0.09,0.09,0.1,0.08,0.09,0.09,0.08,0.1,0.09,0.1,0.13,0.06,0.09,0.1,0.1,0.09,0.11,0.09,0.08,0.08,0.09,0.08,0.06,0.08,0.06,0.08,0.06,0.07,0.08,0.07,0.1,0.08)
sector <- c("Telecommunication Services","Telecommunication Services","Telecommunication Services","Telecommunication Services","Telecommunication Services","Utilities","Utilities","Utilities","Utilities","Utilities","Utilities","Utilities","Utilities","Utilities","Utilities","Utilities","Utilities","Utilities","Utilities","Utilities","Utilities","Utilities","Utilities","Utilities","Utilities","Utilities","Utilities","Utilities","Utilities","Utilities","Utilities","Utilities","Utilities","Energy","Energy","Energy","Energy","Energy","Energy","Energy","Energy","Energy","Energy","Energy","Energy","Energy","Energy","Energy","Energy","Energy","Energy","Energy","Energy","Energy","Energy","Energy","Energy","Energy","Energy","Energy","Energy","Energy","Energy","Energy","Energy","Energy","Energy","Energy","Energy","Energy")
df <- data.frame(wacc, sector)
ggplot(df, aes(df$wacc))+stat_density()+facet_wrap(~sector)

0 个答案:

没有答案