我找到了一个解决方法,使用Envstats包。需要下载、加载和激活此包:
library(Envstats)
stripChart(与stripchart不同)会向图表中添加一些值,例如n值。首先我绘制了箱线图。然后我在stripChart中使用了add=T。显然,在stripChart代码中隐藏了许多东西,以便它们不会显示在箱线图上。这是我用于stripChart的代码,以隐藏大多数项目。
Boxplot带有集成的stripChart以显示n值:
stripChart(data.frame(T0_G1,T24h_G1,T96h_G1,T7d_G1,T11d_G1,T15d_G1,T30d_G1), show.ci=F,axes=F,points.cex=0,n.text.line=1.6,n.text.cex=0.7,add=T,location.scale.text="none")
箱线图
boxplot(data.frame(T0_G1,T24h_G1,T96h_G1,T7d_G1,T11d_G1,T15d_G1,T30d_G1),main="All Rheometry Tests on Egg Plasma at All Time Points at 0.1Hz,0.1% and 37 Set 1,2,3", names=c("0h","24h","96h","7d ", "11d", "15d", "30d"),boxwex=0.6,par(mar=c(8,4,4,2)))
然后是stripChart
stripChart(data.frame(T0_G1,T24h_G1,T96h_G1,T7d_G1,T11d_G1,T15d_G1,T30d_G1), show.ci=F,axes=F,points.cex=0,n.text.line=1.6,n.text.cex=0.7,add=T,location.scale.text="none")
您可以随时调整数字(n值)的高度,以使其适合您想要的位置。
geom_boxplot(aes(fill=factor(f2)))
进行ggplot绘图,其中f2是第二个因子-是否有一种变化的stat_summary可以使“子框”接收自己的N? - J Millerggplot(mpg, aes(manufacturer, hwy, fill = factor(year))) + geom_boxplot() + stat_summary(fun.data = give.n, geom = "text", position = position_dodge(height = 0, width = 0.75), size = 3)
您可能需要手动调整传递给position_dodge()
中的width
值。 - JoFrhwld