我喜欢创建一个带有中间标签的boxplot
和一个中间值和n的汇总表(每组观察的数量),在底部和y轴标签旋转90度。
这是我的测试数据集
exampledf <- data.frame( val=c(4, 2, 3, 5, 4, 1, 5, 8),
let=c("a", "a", "a", "b", "b", "c", "c", "c") )
我能做这些
boxplot(val ~ let, data = exampledf)
不知道如何旋转y轴标签90,添加中值值和下面的n表.预期数字
发布于 2022-10-18 20:31:51
我们可以使用boxplot
的不可见输出来获得中介和ns。对于面板下面的中间标签和类表对象,我们可以使用text
和mtext
函数以及lines
。我们最好使用png
设备。
png('myplot.png', 600, 400)
par(mar=c(7, 4, 4, 2)+.1)
b <- boxplot(val ~ let, data=exampledf, xlab='', las=1)
mds <- b$stats[3, ]
text(1:3, mds + .225, labels=formatC(mds,format='f', digits=2), cex=.8)
mtext(c('n', b$n), 1, 2.5, at=c(.5, 1:3)-.05, adj=0)
mtext(c('median', formatC(mds,format='f', digits=2)), 1, 3.5, at=c(.5, 1:3)-.05, adj=0)
lines(c(.75, 3.25), c(-.25, -.25), xpd=TRUE)
lines(c(.75, 3.25), c(-1.5, -1.5), xpd=TRUE)
mtext('let', line=1)
dev.off()
https://stackoverflow.com/questions/74119722
复制相似问题