【发布时间】:2016-01-26 09:01:13
【问题描述】:
我有一个包含 3 个因素(Parent.organization、Hierarchy、变量)以及一个度量变量(值)的数据集,可以使用一些帮助。以下是一些相同风格的示例数据:
sampleData <- data.frame(id = 1:100,
Hierarchy = sample(c("Consultant", "Registrar", "Intern", "Resident"), 100, replace = TRUE),
Parent.organization = sample(c("Metropolitan", "Regional"), 100, replace = TRUE),
variable = sample(c("CXR", "AXR", "CTPA", "CTB"), 100, replace = TRUE),
value = rlnorm(20, log(10), log(2.5)))
summary(sampleData)
使用下面的代码,我得到了下面的图表
library(ggplot2)
library(scales)
p0 = ggplot(sampleData, aes(x = Hierarchy, y = value, fill = variable)) +
geom_boxplot()
plog = p0 + scale_y_log10(breaks = trans_breaks("log10", function(x) 10^x),
labels = trans_format("log10", math_format(10^.x))) +
theme_bw() +
facet_grid(.~Parent.organization, scales = "free", space = "free")
我想要为每个扫描变量标记一组值(这些值在层次结构的所有元素中都是相同的,并且代表真实值)。假设它们分别是 AXR、CTB、CTPA、CXR 的 3、5、7、5。我希望将这些叠加在顶部,但我不确定如何进行。
我正在寻找类似的东西(我刚刚填写了前两个,但相同的模式将全面适用):
我对 R 的了解正在提高,但我想说我仍然相当无能。也非常欢迎任何关于如何改进我的问题的建议。
【问题讨论】:
标签: r ggplot2 data-visualization boxplot