如何在 ggplot2 中仅使用一个命令来增加点和文本的大小?
我正在为海报和幻灯片绘制一些图表。我需要更大的点和更大的文字。我读到了 ggplot2 的 theme_set 和 theme_update。据我所知,只有两个预设主题,它们的不同之处在于背景的颜色排列。但是,我想让所有文本更大,绘制点更大。
我学会了如何更改字体大小。
theme_update(axis.text.x=theme_text(size=30))
但这只会改变轴文本。我必须对一堆其他参数(axis.text.y、axis.title.x 等)做同样的事情。称我为“懒惰”,但我想要一个可以增加所有文本(最好也包括绘制点)的基本尺寸的命令。是否有一个或两个命令涵盖所有参数?或者还有其他固定主题吗?
I am plotting some graphs for a poster and a slideshow. I need bigger points and bigger text. I read about ggplot2's theme_set and theme_update. From what I can tell there are only two preset themes and they differ by the color arrangement of the background. However, I want to make all the text bigger and the plotted points bigger.
I learned how to change the font size.
theme_update(axis.text.x=theme_text(size=30))
But that only changes the axis text. I would have to do the same thing for a bunch of other parameters (axis.text.y, axis.title.x etc). Call me "lazy" but I want a single commands that can increase the base size for all text (and preferably the plotted points too). Is there one or two commands that covers all parameters? Alternatively are there any other set themes?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您对两个默认主题中任何一个的颜色都满意,则两者都采用文本基本大小的参数。这会延续到绘图周围的所有文本(带缩放)。您只需将
theme_gray(30)
添加到您的绘图中即可。对此有一点需要注意。如果您随后使用them_text设置文本的其他参数,则必须重新指定大小。或者,您可以获取
theme_gray
(或theme_bw
,以更接近者为准)的代码,并直接在其中进行任何主题更改。有关如何执行此操作的示例,请查看 ggplot2 wiki: https://github.com/hadley /ggplot2/wiki/Themes编辑:
例如:
If you are fine with the colors of either of the two default themes, both take an argument of a base size for text. This is carried over to all the text around the plot (with scaling). You can just add
theme_gray(30)
to your plots. One caveat to that. If you afterward set other parameters of text with them_text, you have to respecify the size.Alternatively, you can take the code for
theme_gray
(ortheme_bw
, whichever is closer) and make any thematic changes directly there. For examples of how to do that, check the ggplot2 wiki: https://github.com/hadley/ggplot2/wiki/ThemesEDIT:
As an example: