मैं एक वैकल्पिक समाधान प्रदान करना चाहता हूं, जो मैं प्रस्तावित करने वाला हूं उसके समान एक मजबूत समाधान ggtern के नवीनतम संस्करण में आवश्यक था , जब से कैनवास रोटेशन की सुविधा शुरू की गई थी।
मूल रूप से, आपको त्रिकोणमिति का उपयोग करके सापेक्ष पदों को निर्धारित करने की आवश्यकता है, एक फ़ंक्शन का निर्माण करके जो किसी element_textऑब्जेक्ट, दिए गए कोण (यानी डिग्री) और स्थिति (यानी x, y, शीर्ष या दाएं में से एक) की जानकारी देता है।
#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)
}
सच कहूँ तो, मुझे लगता है कि, एक 'ऑटो' विकल्प को और तर्कों के ggplot2लिए उपलब्ध कराया जाना चाहिए , जब कोण को निर्दिष्ट करते हुए, वैसे भी, यह प्रदर्शित करता है कि उपरोक्त कैसे काम करता है।hjustvjust
#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)
जो निम्नलिखित उत्पादन करता है:

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