但是,直方图的“基数”与x轴上的特定值不对齐。最好是,我希望x轴单元数以直方图的底为中心。
我的数据
p <– structure(list(WHO.Grade = c(1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 3L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L), ki67pro = c(4L, 3L, 4L, 4L, 7L, 6L, 4L, 1L, 4L, 12L, 4L, 3L, 1L, 2L, 20L, 10L, 3L, 3L, 3L, 5L, 3L, 3L, 4L, 5L, 2L, 4L, 5L, 3L, 15L, 4L, 4L, 4L, 4L, 2L, 4L, 2L, 2L, 3L, 7L, 5L, 4L, 2L, 4L, 6L, 4L, 3L, 5L, 4L, 2L, 3L, 3L, 5L, 8L, 0L, 3L, 2L, 20L, 4L, 4L, 4L, 3L, 5L, 5L, 12L, 3L, 2L, 2L, 3L, 3L, NA, 4L, 3L, 3L, 12L, 4L, 1L, 3L, 8L, 7L, 4L, 5L, 3L, 3L, 3L, 3L, 1L, 4L, 5L, 2L, 3L, 3L, 5L, 7L, NA, 2L, 12L, 4L, 0L, 4L, 3L, 10L, 5L, 4L, 3L, 20L, 10L, 10L, 3L, 2L, 10L, 4L, 5L, 3L, 2L, 4L, 2L, 5L, 2L, 4L, 25L, 3L, 5L, 3L, 4L, 7L, 0L, 5L, 7L, 1L, 1L, 1L, 4L, 4L, 6L, 5L, 7L, 3L, 3L, NA, 3L, 4L, 3L, 5L, 10L, 1L, 2L, 3L, 2L, 4L, 5L, 4L, 3L, 4L, 3L, 3L, 7L, 3L, 4L, 3L, 4L, 5L, 6L, 3L, 2L, 3L, 4L, 5L, 3L, 4L, 2L, 4L, 5L, 5L, 12L, 12L, 7L)), .Names = c("WHO.Grade", "ki67pro"), class = "data.frame", row.names = c(NA, -176L))
p1 <- subset(p, p$WHO.Grade==1)
p2 <- subset(p, p$WHO.Grade==2)
p3 <- subset(p, p$WHO.Grade==3)
我使用了以下脚本:
q <- ggplot() + theme_grey() +
scale_x_continuous(name="The Ki-67/MIB-1 LI percetage", limits=c(-1, 26), seq(-1,26,by=1)) +
scale_y_continuous(name="Patients diagnosed", limits=c(0, 44), seq(0,44,by=2)) +
geom_histogram(aes(x=p1$ki67pro), colour="#222a37", fill="#222a37", bins=40, alpha=0.30) +
geom_histogram(aes(x=p2$ki67pro), colour="dodgerblue2", fill="dodgerblue2", bins=40, alpha=0.35) +
geom_histogram(aes(x=p3$ki67pro), colour="darkred", fill="darkred", bins=40, alpha=0.35) +
geom_density(aes(x=p$ki67pro, y=..count..), colour="orange", fill="white", alpha=0) +
geom_hline(yintercept=0, colour="white", size=0.9)
q
谢谢C。