我正在尝试用一些文本注释我的 ggplot 图,但我很难找到最佳解决方案。我想在图的右侧创建一个边距,以便我可以写课程 A、课程 B 和课程 C。现在我没有足够的空间。我尝试使用 plot.margin = unit(c(1,4,1 ,1), "cm") 但这似乎并没有给我可以用来注释情节的空间。ggplot 中有我可以使用的功能吗?
trainingplot <- ggplot(aggreg.data, aes(x = trainingblock, y = performance)) +
scale_y_continuous(name = "Time substracted from straight gliding time (sec.)", breaks = seq(-2, 6, 1)) +
scale_x_discrete() +
theme_pubr()+
theme(legend.position="none",
axis.title.x=element_blank(),
plot.margin = unit(c(1,4,1 ,1), "cm")) +
geom_hline(aes(yintercept = 0), linetype = "dashed", size=0.2) +
annotate("text", x = 5.4, y = -0.4, label = "Course A", size=4) +
annotate("text", x = 5.4, y = 0.5, label = "Course B", size=4) +
annotate("text", x = 5.4, y = 2, label = "Course C", size=4)