[我正在尝试生成一个图表,显示在几种不同条件下单个结果的百分比如何变化。
我正在粘贴分配了SampleData的示例data.frame对象的dput输出:
SampleData <- structure(list(Patient = c(7L, 29L, 10L, 6L, 14L, 11L, 28L, 21L,
5L, 18L, 4L, 1L, 24L, 20L, 22L, 23L, 19L, 3L, 12L, 30L), Symptom_Dur = structure(c(2L,
1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L,
2L, 2L, 2L), .Label = c("<2.5 Months", ">2.5 Months"), class = "factor"),
Outcome = structure(c(2L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L,
2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("Better w/ Steroids",
"Needed Surgery"), class = "factor")), row.names = c(NA,
-20L), class = "data.frame")
特别是,我试图生成一个图表,显示症状少于2.5个月时需要手术的患者百分比与症状超过2.5个月时需要手术的患者百分比。 (我也可能在将来的另一个时间点查看)。
我曾尝试使用x =结果制作条形图,并按症状持续时间进行刻面,如下所示,但我无法获得排除“更好的类固醇”的垃圾箱的图表:
SampleData %>%
ggplot() +
geom_bar(mapping = aes(x = Outcome, y = stat(prop), group = 1)) +
facet_wrap(~ Symptom_Dur)
我正在寻找类似于以下情节的内容:
注意,以上图像仅显示了“需要手术”的患者百分比。我试图避免使用包含[[both w / Steroids]和“ Needed Surgery”患者的数据的图。谢谢!
我正在尝试生成一个图表,显示在几种不同条件下单个结果的百分比如何变化。我正在粘贴分配了SampleData:...
x = Symptom_Dur
而不是x = Outcome
并删除facet_wrap
部分。然后只需编辑实验室并添加标题。