我正在使用ggplot从均值和SD摘要数据制作线图。
我正在使用ggsignif软件包中的geom_signif()函数标记明显的差异。
x轴上两个最终点(第2天和第3天)之间的比较均未显示。其他所有有意义的标签都工作正常。为什么这些比较结果不能显示其他所有工作正常的时间?
我已经复制了示例图像的代码,并附加了它创建的图。
我在面板图中的所有绘图都遇到相同的问题。
ortho_theme = theme(plot.title = element_text(face = "bold"),
axis.text.x = element_text(face = "bold", colour = "black", angle = 15, size = 12, hjust = 1),
axis.text.y = element_text( colour = "black", size = 12),
axis.title.y = element_text(face = "bold", colour = "black", size = 14),
legend.text = element_text(colour = "black", size = 12),
legend.title = element_text(face = "bold", colour = "black", size = 12))
(brain =
ggplot(Ortho_data, aes(x = Day, y = Cerebral_TOI_mean, group = factor(Condition), fill = factor(Condition))) +
geom_errorbar(data = (Ortho_data %>% filter(Condition == "Stand")),
aes(ymax = (Cerebral_TOI_mean),
ymin = (Cerebral_TOI_mean - Cerebral_TOI_SD)), width = 0.1) +
geom_errorbar(data = (Ortho_data %>% filter(Condition == "Supine")),
aes(ymin = (Cerebral_TOI_mean),
ymax = (Cerebral_TOI_mean + Cerebral_TOI_SD)), width = 0.1) +
geom_line() +
geom_point(size = 4, shape = 21) +
ggtitle("A") +
ylab("Cerebral TOI (%)") +
xlab("") +
ylim(50, 85) +
scale_fill_manual(values = c("black", "grey"), name = "Condition")+
theme_classic() +
ortho_theme +
annotate("text", x = 0.935, y = 78.6, label = "*", hjust = 0, size = 5) +
geom_signif(comparisons = list(c("Sea level", "Day 2")), annotation = "‡", y_position = 82, vjust = -0.3, textsize = 3,
tip_length = c(0.1, 0.02))+
geom_signif(comparisons = list(c("Day 1", "Day 2")), annotation = "‡", y_position = 70, colour = "black", vjust = -0.3, textsize = 3,
tip_length = c(0.1, 0.02))+
geom_signif(comparisons = list(c("Day 1", "Day 3")), annotation = "‡", y_position = 75, colour = "black", vjust = -0.3, textsize = 3,
tip_length = c(0.05, 0.2))+
geom_signif(comparisons = list(c("Day 2", "Day 3")), annotation = "‡", y_position = 70, colour = "black", vjust = -0.3, textsize = 3)
)
我已通过将组美学从ggplot aes移至geom_line aes来解决此问题,如以下最小可重复的示例。
这解决了问题,但是我不明白为什么...
library(ggplot2)
library(ggsignif)
data = data.frame(Day = factor(c("Sea level", "Day 1", "Day 2", "Day 3", "Sea level", "Day 1", "Day 2", "Day 3"),
levels = c("Sea level", "Day 1", "Day 2", "Day 3")),
Condition = c("Supine", "Supine", "Supine", "Supine", "Stand", "Stand", "Stand", "Stand"),
Values = c(1,1,2,4,2,2,3,5))
ggplot(data, aes(x = Day, y = Values)) +
geom_line(aes(group = Condition)) +
geom_point()+
geom_signif(comparisons = list(c("Day 2", "Day 3")), annotation = "‡")