Tôi muốn cung cấp một giải pháp thay thế, một giải pháp mạnh mẽ tương tự như những gì tôi sắp đề xuất được yêu cầu trong phiên bản mới nhất của ggtern , kể từ khi giới thiệu tính năng xoay canvas.
Về cơ bản, bạn cần xác định các vị trí tương đối bằng cách sử dụng lượng giác, bằng cách xây dựng hàm trả về một element_textđối tượng, góc đã cho (nghĩa là độ) và định vị (tức là một trong các thông tin x, y, trên cùng hoặc bên phải).
#Load Required Libraries
library(ggplot2)
library(gridExtra)
#Build Function to Return Element Text Object
rotatedAxisElementText = function(angle,position='x'){
angle = angle[1];
position = position[1]
positions = list(x=0,y=90,top=180,right=270)
if(!position %in% names(positions))
stop(sprintf("'position' must be one of [%s]",paste(names(positions),collapse=", ")),call.=FALSE)
if(!is.numeric(angle))
stop("'angle' must be numeric",call.=FALSE)
rads = (angle - positions[[ position ]])*pi/180
hjust = 0.5*(1 - sin(rads))
vjust = 0.5*(1 + cos(rads))
element_text(angle=angle,vjust=vjust,hjust=hjust)
}
Thành thật mà nói, theo tôi, tôi nghĩ rằng nên có sẵn tùy chọn 'tự động' ggplot2cho các đối số hjustvà vjustđối số, khi chỉ định góc, dù sao đi nữa, hãy cho thấy cách thức hoạt động ở trên.
#Demonstrate Usage for a Variety of Rotations
df = data.frame(x=0.5,y=0.5)
plots = lapply(seq(0,90,length.out=4),function(a){
ggplot(df,aes(x,y)) +
geom_point() +
theme(axis.text.x = rotatedAxisElementText(a,'x'),
axis.text.y = rotatedAxisElementText(a,'y')) +
labs(title = sprintf("Rotated %s",a))
})
grid.arrange(grobs=plots)
Mà sản xuất như sau:

q + theme(axis.text.x=element_text(angle = -90, hjust = 0))