ggplot使用math_format()时无法设置x轴轴标签字体加粗怎么解决?
问题原因
math_format()生成的标签为plotmath数学表达式格式,element_text()中的face参数仅对普通文本生效,无法控制数学表达式的字体粗细,因此x轴加粗设置不生效;颜色、大小、角度属于文本通用渲染属性,不受格式类型限制,所以可以正常修改。
修复方案
直接在math_format的表达式参数外层嵌套bold()语法,给数学表达式本身添加加粗属性即可,修改后可运行代码如下:
library(ggplot2) library(scales) a <- ggplot(msleep, aes(bodywt, brainwt)) + geom_point(na.rm = TRUE) + scale_x_log10( breaks = trans_breaks("log10", function(x) 10^x), labels = trans_format("log10", math_format(bold(10^.x))))+ scale_y_log10()+ theme(axis.text.x = element_text(size=10, face="bold", color = "black"), axis.text.y = element_text(size=10, face="bold", color = "black")) a
内容的提问来源于stack exchange,提问作者dnem
相关产品推荐
相关产品推荐

