r语言 - 更改轴标签字体大小时出现问题



我实际上有一个非常简单的问题。

我正在使用 ggplot2 代码来更改轴文本和标签的字体大小。但是,无论我在哪里放置命令,轴上都看不到任何更改。所有其他命令都在工作,所以我得到的印象是某些东西正在"覆盖"主题(axis.text...,axis.title...(命令。

ggplot(Cannock, aes(x=Capacity,color=CPType)) + 
geom_histogram(fill="white",position="identity",binwidth=3,lwd=1) + 
labs(title="Cannock Chase",x="Capacity", y = "Count") + 
theme(axis.text=element_text(size=14), axis.title=element_text(size=16,face="bold")) + 
facet_grid(CPType ~ .) + 
geom_vline(data=mu1, aes(xintercept=grp.mean, color=CPType), linetype="dashed",size=1) + 
theme_bw() + 
theme(axis.line = element_line(colour = "black"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.border = element_blank(),
panel.background = element_blank()) + 
theme(legend.position="none") + 
theme(strip.text.y = element_text(size=8, fac[![enter image description here][1]][1]e="bold"), strip.background = element_rect(colour="white", fill="white")) + 
coord_cartesian(xlim = c(0,100)) + 
theme(strip.background = element_blank(), strip.text = element_blank())

对此的任何指示将不胜感激。非常感谢!

我认为可能是您在更改轴文本格式后调用了theme_bw()。要从默认值更改的任何格式都需要在调用theme_bw后进行更改。此外,为了更干净、更紧密,您可以将所有theme参数组合到一个组中,以便更轻松地跟踪正在更改的内容。下面的代码能解决问题吗?

您还可以使用不同的设置指定strip.textstrip.background两次,这可能不是您想要执行的操作。

ggplot(Cannock, aes(x=Capacity,color=CPType)) + 
geom_histogram(fill="white",position="identity",binwidth=3,lwd=1) + 
labs(title="Cannock Chase",x="Capacity", y = "Count") + 
facet_grid(CPType ~ .) + 
geom_vline(data=mu1, aes(xintercept=grp.mean, color=CPType), linetype="dashed",size=1) + 
theme_bw() + 
coord_cartesian(xlim = c(0,100)) +
theme(axis.text=element_text(size=14), 
axis.title=element_text(size=16,face="bold"),
axis.line = element_line(colour = "black"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.border = element_blank(),
panel.background = element_blank(),
legend.position="none",
strip.text.y = element_text(size=8, face="bold"), 
strip.text = element_blank(),
strip.background = element_rect(colour="white", fill="white"),
strip.background = element_blank())

最新更新