ggplots2 ggsave文字大小不变 [英] ggplots2 ggsave text size not changing

查看:491
本文介绍了ggplots2 ggsave文字大小不变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在更改标题大小,X-Y标签,X-Y轴文本时遇到了问题,这些文本是我的 ggplot2 。我使用 ggsave 将图表保存为jpg。

I'm having issues with changing the size of the title, X-Y labels, X-Y axis text for my ggplot2. I'm using ggsave to save the plot as a jpg.

p <- ggplot()
p + theme(axis.title = element_text(size=30), axis.text.y = element_text(size=30),
          axis.text.x = element_text(size=30))

但改变这些文本的大小并不会改变图上的任何内容。有人会知道如何正确地更改文本大小吗?

but changing the sizes of these texts doesn't change anything on the plot. Would anyone know how to properly change the text sizes?

因此,我解决了我遇到的问题,以主题不会影响情节(我已经测试过改变文字颜色),但轴文字的大小仍然不会改变。

So I fixed the issue I was having so the changes I make to theme are not affecting the plot (I've tested with changing text color), however the size of the axis text still does not change.

p <- ggplot(d[d$user==i,], aes(x=date, y=url, group=user, label=user)) + geom_line() + geom_point() +
  labs(list(title=i, x="Date and Time", y = "URL")) +   # Plot labels
  axis.POSIXct(1, at=seq(daterange[1], daterange[2], by="hour")) # Set x axis range to first and last date-time in data
p <- p + modifiedtheme
ggsave(plot = p, filename = "sample.jpg", height=2, width=6)


推荐答案

这是一个最小的,完全可重现的问题版本(或者没有任何问题,正如评论指出的那样)。您自己发布的代码看起来是正确的,但是这个例子可能会帮助您解决任何真正的问题:

Here is a minimal, fully reproducible version of the problem (or lack of any problem, as comments have pointed out). Your own posted code appears to be correct, but maybe this example will help you solve whatever the real problem is:

library(ggplot2)

p1 = ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width, colour=Species)) + 
     geom_point()

p2 = ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width, colour=Species)) + 
     geom_point() + 
     theme(axis.title=element_text(size=30))

ggsave("figure1.jpg", plot=p1, height=3, width=4, units="in", dpi=150)
ggsave("figure2.jpg", plot=p2, height=3, width=4, units="in", dpi=150)

这篇关于ggplots2 ggsave文字大小不变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆