我想更改 ggplot2 中所有 8 个症状的条带文本位置。我在 strip.text.y 选项中尝试了不同的角度(0,90,180,270,360),但它没有从垂直位置翻转标签。
p = ggplot(data=RR_data,
aes(x = Group,y = LikelihoodRatio, ymin = LowerLimit, ymax = UpperLimit))+
geom_hline(yintercept=1,linetype=2)+
geom_pointrange(aes(col=Group))+
xlab('Symptom')+ guides(colour = guide_legend(reverse=T)) + ylab("Likelihood Ratio (95% Confidence Interval)")+
geom_errorbar(aes(ymin=LowerLimit, ymax=UpperLimit,col=Group),width=0.1,cex=1)+
facet_wrap(~Symptom,strip.position="left",nrow=22, scales = "free_y") +
theme(plot.title=element_text(size=16,face="bold",angle = 180),panel.background = element_rect(fill="white", colour="Grey"),
axis.text.y=element_blank(),
axis.ticks.y=element_blank(),
axis.text.x=element_text(face="bold"),
axis.title=element_text(size=10,face="bold"),
strip.text.y = element_text(hjust=0, vjust=1, angle=180,face="bold"),
strip.background.y = element_rect(fill="white", colour="grey"))+
coord_flip()
p
Run Code Online (Sandbox Code Playgroud)
恐怕这是一个没有记录的案例,但您可以使用strip.text.y.left. 我采用了标准数据集来说明问题,因为我无法重现您的代码。
ggplot(iris, aes(Sepal.Width, Sepal.Length)) +
geom_point() +
facet_wrap(~ Species, strip.position = "left") +
theme(strip.text.y.left = element_text(angle = 45))
Run Code Online (Sandbox Code Playgroud)
该问题在 ggplot 中已知:https ://github.com/tidyverse/ggplot2/issues/3888