【发布时间】:2023-03-04 19:46:02
【问题描述】:
我所拥有的是一些我想用长 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。如何在具有多个方面的图上将前者的包装与后者的 plotmath 解析结合起来?
#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
This answer 本来可以让我接近但它不再起作用了。
【问题讨论】: