जहां तक मुझे पता नहीं है, इसलिए मैंने strwidth()
का उपयोग करके एक समाधान का सहारा लिया है, जो मूल ग्राफिक्स में पाठ की चौड़ाई की गणना करता है।
title <- "This is a really excessively wide title for a plot, especially since it probably won't fit"
उपयोग par("din") to get the width of the device, and
strwidth() `पाठ आकार की गणना करने के लिए:
par("din")[1]
[1] 8.819444
strwidth(title, units="inches")
[1] 11.47222
एक समारोह में यह प्रयोग करें और साजिश:
wrapTitle <- function(x, width=par("din")[1]){
xx <- strwrap(x, width=0.8 * nchar(x) * width/strwidth(x, units="inches"))
paste(xx, collapse="\n")
}
wrapTitle(title)
[1] "This is a really excessively wide title for a plot, especially since it\nprobably won't fit, meaning we somehow have to wrap it"
साजिश:
ggplot(mtcars, aes(wt, mpg)) + geom_point() + opts(title=wrapTitle(title))
आप फाइल करने के लिए साजिश को बचाने के लिए चाहते हैं, तो आप वास्तविक बचाया साजिश आयामों के साथ par("din")
बदल सकते हैं।
अच्छा प्रश्न: एक * पुनरुत्पादित * उदाहरण उत्तर की गति हो सकता है ... –
डेटा के बिना उत्तर पोस्ट करना मुश्किल है। लेकिन AFAIK में 'ggplot2' में कोई विकल्प नहीं है, लेकिन आप कुछ लंबाई के बाद' \ n 'डालने के लिए एक फ़ंक्शन लिख सकते हैं। –