R: bold numbers in plot annotation created by plotmath

♀尐吖头ヾ 提交于 2019-12-31 04:27:13

问题


I build graphics in which I use regular and bold font for titles and/or labels. They contain symbols, text and numbers which I combine using ?plotmath.

I noticed that using bold within the expression changes only character strings to bold face, but not numbers which are part of the expression. See this minimal example:

x <- y <- 1:10
plot(x, y, xlab=bquote(bold(foo[bar]^2==.(mean(x)))))

In this example, there is a numeric superscript on the LHS, and an evaluated expression on the RHS of the equality sign. Both of which are not printed in bold face as suggested by using bold. When I change these to character strings, the plot shows them in bold.

plot(x, y, xlab=bquote(bold(foo[bar]^"2"==.(as.character(mean(x))))))

Now, for me it is not always desirable to work with character input in these expressions. I would like to find a way of setting the numeric values in bold without converting them to character strings. (I'm also not sure what to expect of the equality sign.)

Additionally, I use Cairo to select specific fonts for my graphics. In my actual graphics, where I also plot greek letters, I use it to set the "symbol" fonts to bold. By setting the "regular" font to bold, I could do the same for numbers, but that would affect all remaining text as well.

Therefore, I would appreciate if there is a solution that doesn't require to change the default font in the Cairo device.

EDIT:

As mentioned in the comments, plotmath does not apply bold to numeric constants as in the example above. I would still like to see if there is a solution that allows to set numbers in lables/titles to bold without changing the rest of the plot (as for example Cairo would).

Thanks!

来源:https://stackoverflow.com/questions/26282128/r-bold-numbers-in-plot-annotation-created-by-plotmath

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!