IHWpaper 1.24.0
装饰图案为复层柱状图生成的例子。
库(ggplot2)库(“cowplot”)
set.seed (1) < - 10000 binwidth < - 0.025 #普通函数来添加一些属性gg直方图gg_hist_aesthetic < -函数(gg_obj ylim_max = 650) {gg_obj + scale_x_continuous(扩大= c (0.02, 0)) + scale_y_continuous(扩大= c(0.02, 0),限制= c (0, ylim_max)) + xlab(假定值)+ ylab(“计数”)+主题(轴。title = element_text(=“大胆”,大小= rel (0.1)))}
pv_unif < - data.frame (pvalue = runif (m)) gg_unif < - ggplot (pv_unif, aes (x = pvalue)) + geom_histogram (binwidth = binwidth边界= 0,颜色=“lightgrey”,填补= " # 939598)+ geom_hline (yintercept = m * binwidth,大小= 2,=“darkblue”)上校gg_unif < - gg_hist_aesthetic gg_unif (gg_unif)
ggsave(情节= gg_unif文件= " stratified_histograms_unif。pdf”,宽度= 4,身高= 3)
pv_beta_1 < - data.frame (pvalue = c (runif (9000), rbeta (1000 0.5, 7))) gg_beta_1 < - ggplot (pv_beta_1, aes (x = pvalue)) + geom_histogram (binwidth = binwidth边界= 0,颜色=“lightgrey”,填补= " # 939598)+ geom_hline (yintercept = 9000 * binwidth大小= 1.3,=上校darkblue) gg_beta_1 < - gg_hist_aesthetic gg_beta_1 (gg_beta_1)
ggsave(情节= gg_beta_1文件= " stratified_histograms_beta1。pdf”,宽度= 4,身高= 3)
pv_beta_2 < - data.frame (pvalue = c (runif (5500), rbeta (4500、1、4))) gg_beta_2 < - ggplot (pv_beta_2, aes (x = pvalue)) + geom_histogram (binwidth = binwidth边界= 0,颜色=“lightgrey”,填补= " # 939598)+ geom_hline (yintercept = 5500 * binwidth大小= 1.3,=上校darkblue) gg_beta_2 < - gg_hist_aesthetic gg_beta_2 (gg_beta_2)
ggsave(情节= gg_beta_2文件= " stratified_histograms_beta2。pdf”,宽度= 4,身高= 3)
gg_stratified < plot_grid (gg_unif、gg_beta_1 gg_beta_2, nrow = 1,标签= c (”)”、“b)”、“gg_stratified c)”))
ggsave(情节= gg_stratified文件= " stratified_histograms。pdf”,宽度= 12,身高= 4)
set.seed (1) < - 10000 binwidth < - 0.05灰色< -“grey41”#通用函数来添加一些属性gg直方图gg_hist_aesthetic < -函数(gg_obj ylim_max = 6) {gg_obj + aes密度(y = . . . .) + scale_x_continuous(扩大= c(0.02, 0),休息时间= c (0、0.5、1)) + scale_y_continuous(扩大= c(0.02, 0),限制= c (0, ylim_max)) + xlab(假定值)+ ylab(“密度”)+主题(轴。title = element_text(=“大胆”,大小= rel (0.7)))}
pv_unif < - data.frame (pvalue = runif (m)) gg_unif < - ggplot (pv_unif, aes (x = pvalue)) + geom_histogram (binwidth = binwidth边界= 0,颜色=灰色,填补=“lightgrey”) gg_unif < - gg_hist_aesthetic gg_unif (gg_unif)
pv_beta_a < - data.frame (pvalue = c (runif (9000), rbeta (1000、0.5、4))) gg_beta_a < - ggplot (pv_beta_a, aes (x = pvalue)) + geom_histogram (binwidth = binwidth边界= 0,颜色=灰色,填补=“lightgrey”) gg_beta_a < - gg_hist_aesthetic gg_beta_a (gg_beta_a)
pv_beta_b < - data.frame (pvalue = c (runif (8000), rbeta (2000 0.5, 11))) gg_beta_b < - ggplot (pv_beta_b, aes (x = pvalue)) + geom_histogram (binwidth = binwidth边界= 0,颜色=灰色,填补=“lightgrey”) gg_beta_b < - gg_hist_aesthetic gg_beta_b (gg_beta_b, ylim_max = 5.5)
pv_all < - rbind (pv_unif、pv_beta_b pv_beta_a) gg_all < - ggplot (pv_all, aes (x = pvalue)) + geom_histogram (binwidth = binwidth边界= 0,颜色=灰色,填补=“lightgrey”) gg_all < - gg_hist_aesthetic gg_all (gg_all)
gg_stratified < plot_grid (gg_all、gg_beta_b gg_beta_a, gg_unif, nrow = 1,标签= c (”)”、“b)”、“c)”、“gg_stratified d)”))
ggsave(情节= gg_stratified文件= " stratified_histograms。pdf”,宽度= 6,身高= 2)