此问题是因为df1和df2数据框的行数不同导致的。解决方法可以是使用dplyr包的left_join()函数将两个数据框按照共有的列合并成一个新的数据框,从而避免行数不同的问题。
示例代码如下:
library(ggpubr)
library(dplyr)
df1 <- data.frame(x = c(1, 2, 3), y = c(4, 5, 6))
df2 <- data.frame(x = c(1, 2, 3), y = c(7, 8, 9))
使用left_join()函数合并两个数据框
df3 <- left_join(df1, df2, by = "x")
使用ggpaired()函数绘制带误差线的组间差异图
ggpaired(df3, x = "x", y = c("y.x", "y.y"), color = "group",
ylim = c(0, 10), line.size = 0.7,
error.plot = "errorbar",
error.plot.width = 0.4,
bar.size = 0.8, position = position_dodge(width = 0.8),
legend.title = "Group",
palette = c("#00AFBB", "#E7B800"),
ggtheme = theme_bw())