我用 ggplot2 創建了一個圖形,顯示了我所做實驗的一些資料點。但是,我找不到適合我的文本標簽的好的解決方案。現在,我將“Acqusitition trial blocks”重復三遍,所以我認為最好只寫一次,然后在刻度點處分別寫上 1、2 和 3。但是我找不到解決這個問題的好方法。最理想的是,我希望解決方案的 Acquisition 試驗塊低于 1、2 和 3。
trainingplot <- ggplot(sample_descriptive, aes(x=trainingblock, y=pointEstimate))
theme_pubr()
scale_y_continuous(name = "Time substracted from straight gliding time (sec.)", limits = c(-1, 5), breaks = c(-1, 0, 1, 2,3,4))
scale_x_discrete(expand = expansion(add = c(.6, 1.2)), labels= c("Pre-test", "Acquisition trial block\n 1", "Acquisition trial block\n 2", "Acquisition trial block\n 3", "Retention (72h)"))
annotate("text", x = 5.5, y = -0.4, label = "Course A", size=4.5)
annotate("text", x = 5.5, y = 0.5, label = "Course B", size=4.5)
annotate("text", x = 5.5, y = 2, label = "Course C", size=4.5)
trainingplot <- trainingplot
geom_errorbar(data = sample_descriptive, aes(x=trainingblock, y = pointEstimate, ymin = lower.CL,ymax = upper.CL, group=interaction(course, group)), position = position_dodge(0.2), size=1, width=0.3)
geom_line(data = sample_descriptive, aes(x=trainingblock, y = pointEstimate, group=interaction(course, group)), position = position_dodge(0.2), alpha=0.4)
geom_point(data = sample_descriptive, aes(x=trainingblock, y=pointEstimate, shape=group, fill=group, group=interaction(course, group)), position = position_dodge(0.2), size=2.8, color="black")
theme(legend.position="none",
axis.title.x=element_blank())
geom_hline(aes(yintercept = 0), linetype = "dashed", size=0.2)
scale_fill_manual(values = c("#1A85FF", "#D41159", "#FFB000"))
scale_shape_manual(values=c(21, 24))

uj5u.com熱心網友回復:
這是一個示例,使用一些編造的資料使其可復制給其他人。正如@tjebo 指出的那樣,您可以通過控制 y 限制coord_cartesian并關閉裁剪來在繪圖區域外進行注釋。
library(ggpubr); library(ggplot2)
sample_descriptive <- data.frame(
trainingblock = LETTERS[1:5],
pointEstimate = 1:5,
course = "A",
group = "Z"
)
ggplot(sample_descriptive, aes(x=trainingblock, y=pointEstimate))
theme_pubr()
scale_y_continuous(name = "Time substracted from straight gliding time (sec.)", breaks = c(-1, 0, 1, 2,3,4))
scale_x_discrete(expand = expansion(add = c(.6, 1.2)), labels= c("Pre-test", "1", "2", "3", "Retention (72h)"))
annotate("text", x = 5.5, y = -0.4, label = "Course A", size=4.5)
annotate("text", x = 5.5, y = 0.5, label = "Course B", size=4.5)
annotate("text", x = 5.5, y = 2, label = "Course C", size=4.5)
annotate("text", x = 3, y = -2, label = "Acquisition trial blocks", size = 4 )
# geom_errorbar(data = sample_descriptive, aes(x=trainingblock, y = pointEstimate, ymin = lower.CL,ymax = upper.CL, group=interaction(course, group)), position = position_dodge(0.2), size=1, width=0.3)
geom_line(data = sample_descriptive, aes(x=trainingblock, y = pointEstimate, group=interaction(course, group)), position = position_dodge(0.2), alpha=0.4)
geom_point(data = sample_descriptive, aes(x=trainingblock, y=pointEstimate, shape=group, fill=group, group=interaction(course, group)), position = position_dodge(0.2), size=2.8, color="black")
theme(legend.position="none",
axis.title.x=element_blank(), plot.margin = unit(c(0,0,2,0), "line"))
coord_cartesian(ylim = c(-1, 5), clip = "off")
geom_hline(aes(yintercept = 0), linetype = "dashed", size=0.2)
scale_fill_manual(values = c("#1A85FF", "#D41159", "#FFB000"))
scale_shape_manual(values=c(21, 24))

轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/342998.html
上一篇:忽略熱圖中著色的特定值
