Nếu bạn muốn xoay nhãn trục x với góc bằng hoặc nhỏ hơn 90, hãy thử các phương pháp sau đây:
Nó sử dụng lập luận của barplot space=1
để làm chiều rộng của cột bằng không gian khoảng của các cột.
Bằng cách này, có thể điều chỉnh mã được cung cấp trong R FAQ được xác định bởi @BenBarnes theo câu trả lời của Tyler Rinker.
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)
![enter image description here](https://i.stack.imgur.com/AJLFk.jpg)
Nguồn
2014-02-24 03:54:08
_caveat_: Nếu bạn đang sử dụng 'bên cạnh = TRUE', có thể bạn sẽ muốn sử dụng' colMeans (x) 'thay vì chỉ' x' nếu bạn chỉ muốn một nhãn cho mỗi nhóm. – MichaelChirico