请p.plot
在下面找到我的数据
我做了这个情节
不幸的是,似乎每个geom_density
x = 0的初始部分都被遗漏了。该图应如下所示:
该图以前是在StackOverflow的帮助下完成的,该图似乎在起作用。但是,我不知道当前代码/数据管理出了什么问题。
我的密码
cols = c("#1C73C2", "red", "black")
ggplot(p.plot, aes(time.recur.years, colour=ki67in, fill=ki67in)) +
geom_density(aes(y=..count..), alpha=0.2) +
#geom_bar(alpha=0.7) +
geom_rug(aes(y=0), position=position_jitter(width=0.05, height=0),
length=unit(0.05, "npc"), show.legend=FALSE) +
coord_cartesian(xlim=c(0,11)) +
scale_x_continuous(name="Years to recurrence", breaks=0:11, expand=c(0,0)) +
scale_y_continuous(name="Number of recurrences", limits=c(0, 6), breaks=0:6, expand=c(0,0)) +
scale_colour_manual(values=cols) +
scale_fill_manual(values=cols) +
labs(colour="", fill="") +
theme_classic() +
theme(panel.grid.major = element_line(colour = "gray98"),
panel.grid.minor = element_line(colour = "gray98"),
legend.position=c(0.7,0.8))
我的资料
p.plot <- structure(list(time.recur.years = c(0.5, 0.666666666666667, 1,
1.25, 3.16666666666667, 4.08333333333333, 4.41666666666667, 4.75,
4.83333333333333, 4.83333333333333, 5, 6.16666666666667, 7.41666666666667,
7.5, 7.66666666666667, 10.3333333333333, 0.25, 0.333333333333333,
0.416666666666667, 0.666666666666667, 0.75, 1.41666666666667,
3.25, 4.5, 9.83333333333333, 0.166666666666667, 0.333333333333333,
0.583333333333333, 0.666666666666667, 4.66666666666667), ki67in = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L), .Label = c("Ki-67 proliferative index: 0 - 4%",
"Ki-67 proliferative index: 5 - 9%", "Ki-67 proliferative index: ≥10%"
), class = "factor")), class = "data.frame", row.names = c(NA,
-30L))
这在ggplot 3.3.0中似乎是新的-并且是一种不绘制完整多边形的新方法。我发现这实际上很好!
如果您想要一个完整的多边形-现在有一个新的参数outline.type
。也可以看看?geom_density
我还添加了一行数据为0的行,以便将多边形绘制到0。
library(tidyverse)
df_add <- rbind(p.plot, data.frame(time.recur.years = 0, ki67in =unique(p.plot$ki67in)))
ggplot(df_add, aes(time.recur.years, colour=ki67in, fill=ki67in)) +
geom_density(aes(y=..count..), alpha=0.2, outline.type = 'full')
由reprex软件包(v0.3.0)创建于2020-03-28
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句