我有以下数据:
df1< - read.table(text =“ID组值时间A1 A 21 10A2 A 79 20A3 A 32 30B1 B 105 40B2 B 44 50B3 B 58 60C1 C 32 70C2 C 66 80C3 C 143 90“,stringsAsFactors = ……
如果你不依赖 ggboxplot() ,有基本情节的解决方案。
ggboxplot()
boxplot(Value ~ Group, df1, xlim=c(.4, 3.5), xlab="Group", ylab="Value") points(df1$time/100*3.5, df1$Value, pch=16) axis(3, seq(0, 3.5, length.out=11), 0:10*10) mtext("time", 3, 3)
的 说明 强>
我们首先制作一个普通的箱形图并稍微扩展y轴 xlim() 向左(否则从0.5开始)。然后我们覆盖了情节 points() 通过缩放辅助x轴( "time" )到箱线图的x轴的[0,3.5]范围。然后我们添加轴并标记它,最后我们为辅助x轴添加标签 mtext() 。
xlim()
points()
"time"
mtext()
的 结果 强>
的 数据 强>
df1 <- structure(list(ID = c("A1", "A2", "A3", "B1", "B2", "B3", "C1", "C2", "C3"), Group = c("A", "A", "A", "B", "B", "B", "C", "C", "C"), Value = c(21L, 79L, 32L, 105L, 44L, 58L, 32L, 66L, 143L ), time = c(10L, 20L, 30L, 40L, 50L, 60L, 70L, 80L, 90L)), class = "data.frame", row.names = c(NA, -9L))