如果你想旋轉與角度等於或小於90 x軸標籤,請嘗試以下方法:
它使用barplot的說法space=1
使列的寬度等於列的間隔空間。
通過這種方式,我們可以調整由Tyler Rinker的答案根據@BenBarnes指定的R FAQ中提供的代碼。
par(mar = c(7, 4, 2, 2) + 0.2) #add room for the rotated labels
#use mtcars dataset to produce a barplot with qsec colum information
mtcars = mtcars[with(mtcars, order(-qsec)), ] #order mtcars data set by column "qsec" (source: http://stackoverflow.com/questions/1296646/how-to-sort-a-dataframe-by-columns-in-r)
end_point = 0.5 + nrow(mtcars) + nrow(mtcars)-1 #this is the line which does the trick (together with barplot "space = 1" parameter)
barplot(mtcars$qsec, col="grey50",
main="",
ylab="mtcars - qsec", ylim=c(0,5+max(mtcars$qsec)),
xlab = "",
space=1)
#rotate 60 degrees, srt=60
text(seq(1.5,end_point,by=2), par("usr")[3]-0.25,
srt = 60, adj= 1, xpd = TRUE,
labels = paste(rownames(mtcars)), cex=0.65)
_caveat_:如果你使用的是'beside = TRUE',如果你只需要每個組一個標籤,你可能會想用'colMeans(x)'而不是'x'。 – MichaelChirico 2016-10-07 03:59:34