【发布时间】:2021-11-10 13:59:33
【问题描述】:
很遗憾,我的 ggplot 有问题。
这是我的数据框的一个子集:
Name <- c('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16', '17','18','19','20','21','22','23','24','25','26','27','28','29','30','31','32')
Gruppe <-c('A','A','B','B','C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C','A','A','B','B','C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C')
Group <-c('A','A','B','B','CA','CA','GE','GE','SA','SA','ST','ST','STR','STR','WA','WA')
Location <-c('CO','UF','CO','UF','CO','UF','CO','UF','CO','UF','CO','UF','CO','UF','CO','UF','CO','UF','CO','UF','CO','UF','CO','UF','CO','UF','CO','UF','CO','UF','CO','UF')
Value <-c(3.5,6.6,1.9,9.2,5.2,4.4,6.8,3.2,2.7,7.1,4.3,9.8,4,8.3,5,6.1,3,8.4,4.8,9.1,1.4,4,8.9,3.6,4,8.4,6.1,2.5,4.5,9.3,6.7,4.6)
data <- data.frame(Name, Gruppe, Group, Location, Value)
我想用根据“组”分隔的 ggplot 来绘制它。 我的代码:
ggplot(data, aes(x=Location, y=Value, fill=Group)) +
geom_boxplot()+
scale_color_brewer(palette="Paired")+
theme_classic()+
scale_fill_manual(values=c("chartreuse3", "yellow2",
"firebrick3", "cyan4","darkgoldenrod2","darkorange4","darkgreen","deeppink3","darksalmon"))
但是,我还想在“Gruppe”中添加“C”作为应显示在图例中的附加箱线图,总结“CA”-“WA”中的“组”。有什么办法吗?最好在不改变数据集本身的情况下,它的原始形式很大。箱线图应该在“A”和“B”旁边并且看起来相同,即宽度。
示例图片(外观很抱歉): enter image description here
感谢大家的帮助,如有遗漏我会尽力解释。
【问题讨论】:
-
不是对您问题的回答,但如果您只有两个位置,我建议您查看
+facet_wrap(~Location),并在 x 轴上使用Group。在 x 轴上使用Location可能会更好看。
标签: r ggplot2 plot boxplot diagram