微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在R中用两行拟合轴标题?

如何解决如何在R中用两行拟合轴标题?

我使用代码 ylab(expression(paste()

制作了一张带有“两行”y 轴标题的图表
Genotype <- c("CV1","CV2","CV1","CV2")
Category<- c("GN","GN","AGW","AGW")
mean <- c(1.47,1.66,0.98,0.93)
se<- c(0.10,0.20,0.03,0.06)
DataA<- data.frame(Genotype,Category,mean,se)
DataA


ggplot(data=DataA,aes(x=Genotype,y=mean,fill=Category))+
  geom_bar(stat="identity",position="dodge",width = 0.7) + 
  geom_errorbar(aes(ymin= mean-se,ymax=mean + se),position=position_dodge(0.7),width=0.2,size=1) +
  scale_fill_manual(values= c ("Dark gray","Cadetblue")) + 
  scale_y_continuous(breaks = seq(0,2,0.2),labels = scales::percent,limits = c(0,2)) +  
  geom_hline(yintercept=1,linetype="dashed",color = "Dark red",size=1.5) + 
  xlab("Cultivar") +
  ylab(expression(paste("Value of thinning treatment \n relative to unthinning treatment"))) +
  theme(axis.title = element_text (face = "plain",size = 15,color = "black"),axis.text.x = element_text(size= 15),axis.text.y = element_text(size= 15),axis.line = element_line(size = 0.5,colour = "black"))+ 
  windows(width=7,height=5)

enter image description here

y 轴标题被分成两行,但整个标题并没有装在图表内。即使我调整了图形大小的宽度,它也没有应用于轴标题

你能告诉我如何将整个 y 轴标题很好地拟合到图表中,同时保持轴标题的大小(即字体大小= 15)?

谢谢,

解决方法

一种方法是调整边距,为左侧留出更多空间。

library(ggplot2)

ggplot(data=DataA,aes(x=Genotype,y=mean,fill=Category))+
  geom_bar(stat="identity",position="dodge",width = 0.7) + 
  geom_errorbar(aes(ymin= mean-se,ymax=mean + se),position=position_dodge(0.7),width=0.2,size=1) +
  scale_fill_manual(values= c ("Dark gray","Cadetblue")) + 
  scale_y_continuous(breaks = seq(0,2,0.2),labels = scales::percent,limits = c(0,2)) +  
  geom_hline(yintercept=1,linetype="dashed",color = "Dark red",size=1.5) + 
  xlab("Cultivar") +
  ylab(expression(paste("Value of thinning treatment \n relative to unthinning treatment"))) +
  theme(axis.title = element_text (face = "plain",size = 15,color = "black"),axis.text.x = element_text(size= 15),axis.text.y = element_text(size= 15),axis.line = element_line(size = 0.5,colour = "black")) + 
  theme(plot.margin=unit(c(1,0.5,1.2),"cm"))

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?