ggplot2:标签表达式中的字体样式 [英] ggplot2: Font Style in label expression
问题描述
更改字体的面和大小在标签中无需表达即可使用。
p < - ggplot(data = mtcars,aes(x = wt,y = mpg))+ geom_point()
p <-p + labs(x =权重,y =表达式(paste(mpg(,m ^ { - 2 },))))
p <-p + opts(axis.title.x = theme_text(family =serif,face =bold,size = 12,angle = 00,hjust = 0.54 ,vjust = 0))
p <-p + opts(axis.title.y = theme_text(family =serif,face =bold,size = 12,angle = 90,vjust = 0.25))
print(p)
任何帮助将不胜感激。谢谢
我不认为它存在表达式
,尽管你没有确切地说出你看到的是什么,所以很难确定。在Mac上,您可以使用粗体衬线字体显示xlab,但ylab不是粗体(尽管是以衬线显示)。如果我使用plotmath bold
,它将从表达式函数内部成功执行:
p p <-p + opts(axis.title.y = theme_text family =serif,
size = 12,angle = 90,vjust = 0.25))
p < - p + opts(axis.title.x = theme_text(family =serif,face = bold,
size = 12,angle = 00,hjust = 0.54,vjust = 0))
p
与往常一样,图形设备通常是操作系统变量,并且您没有提供任何有关您的提示,因此进一步的评论被禁止。
(编辑:如果你引用指数-2,你可以得到它粗体() - 编辑以及。)
表达式(粗体mpg(m ^ bold( - 2)))))
Changing font faces and sizes works well without expression in the labels. Here is the code where I've problem to change the font faces in label expression.
p <- ggplot(data = mtcars, aes(x=wt, y=mpg))+geom_point()
p <- p + labs(x="Weight", y=expression(paste("mpg ( ", m^{-2}, ")")))
p <- p + opts(axis.title.x = theme_text(family="serif", face="bold", size=12, angle=00, hjust=0.54, vjust=0))
p <- p + opts(axis.title.y = theme_text(family="serif", face="bold", size=12, angle=90, vjust=0.25))
print(p)
Any help would be highly appreciated. Thanks
I do not think it is the presence of expression
, although you don't say exactly what it is that you are seeing so it's difficult to be sure. On a Mac you get the xlab in bold-serif font, but the ylab is not bold (although it is in serif). If I use the plotmath bold
it succeeds from inside the expression function:
p <- p + labs(x="Weight", y=expression( bold(mpg (m^-2) ) ) )
p <- p + opts(axis.title.y = theme_text(family="serif",
size=12, angle=90, vjust=0.25))
p <- p + opts(axis.title.x = theme_text(family="serif", face="bold",
size=12, angle=00, hjust=0.54, vjust=0))
p
As always, graphical devices are often OS-variable and you have not offered any hint about yours, so further commentary is inhibited.
(EDIT: If you quote the exponent -2 you can get it bold()-ed as well.)
expression( bold(mpg (m^bold("-2")) ) ) )
这篇关于ggplot2:标签表达式中的字体样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!