我喜歡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 表。預期數字

uj5u.com熱心網友回復:
我們可以使用不可見的輸出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://www.uj5u.com/qiye/518248.html
標籤:r数据框箱形图
