मेरे पास क्या है कुछ डेटा है जिसे मैं लंबे y अक्ष लेबल के साथ प्लॉट करना चाहता हूं जिसे मैं पहलू लेबल के माध्यम से जोड़ रहा हूं:
library(ggplot2)
data("mtcars")
mtcars$am<-factor(mtcars$am,levels = c("1","0"),
labels = c("paste('Amerikee C (mg C kg ', tuna^-1,')')",#, mg[3]^-phantom(.)-N,', kg ha')^-1",
"paste('Is watchin ',\n,'(mg ', CO[2], ' kg tuna'^-1,d^-1,')')"))
मैं जो चाहता हूं वह है रैपिंग/नई लाइनें (जैसे \n या str_wrap या strwrap) और लेबल में सुपरस्क्रिप्ट और सबस्क्रिप्ट के लिए प्लॉटमैथ।
इस एमएस पेंट मास्टरपीस की तरह।
मैंने जो कोशिश की है वह है label_wrap_gen() और label_parsed। मैं पूर्व के रैपिंग को बाद के प्लॉटमैथ पार्सिंग के साथ, कई पहलुओं वाले प्लॉट पर कैसे जोड़ूं?
#This wraps the labels but doesnt parse the plotmath
ggplot(data=mtcars,aes(x=mpg,y=disp))+
geom_point()+
facet_wrap(am~.,scales=("free_y"),
strip.position = "left",
labeller = label_wrap_gen()) #
labeller=label_parsed)+ylab("")
#This parses the plotmath but doesnt wrap the labels
ggplot(data=mtcars,aes(x=mpg,y=disp))+
geom_point()+
facet_wrap(am~.,scales=("free_y"),
strip.position = "left",
labeller = label_parsed)+ylab("")
#Note also it ignores the \n's i put in the factor labels
इस जवाब से मैं और करीब आ जाता, लेकिन यह अब और काम नहीं करता।
0
CrunchyTopping
11 फरवरी 2021, 23:29
1 उत्तर
सबसे बढ़िया उत्तर
मुझे लगता है कि आप जिस प्लॉटमैथ बिट की तलाश कर रहे हैं वह atop()
फ़ंक्शन है।
library(ggplot2)
data("mtcars")
mtcars$am<-factor(
mtcars$am,levels = c("1","0"),
labels = c("atop('Amerikee C','(mg C kg tuna^-1)')",
"atop('Is watchin','(mg CO'[2]*' kg tuna'^-1*'d'^-1*')')"))
ggplot(data=mtcars,aes(x=mpg,y=disp))+
geom_point()+
facet_wrap(am~.,scales=("free_y"),
strip.position = "left",
labeller = label_parsed)
2021-02-11 को reprex पैकेज (v1.0.0) द्वारा बनाया गया
1
teunbrand
12 फरवरी 2021, 00:04