ggplot2 ggsave 文本大小不变

ggplots2 ggsave text size not changing

我在更改 ggplot2 的标题大小、X-Y 标签、X-Y 轴文本时遇到问题。我正在使用 ggsave 将绘图保存为 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))

但是更改这些文本的大小不会改变情节中的任何内容。有人知道如何正确更改文字大小吗?


所以我解决了我遇到的问题,所以我对主题所做的更改不会影响情节(我已经测试过更改文本颜色),但是轴文本的大小仍然没有改变。

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)

这是问题的一个最小的、完全可重现的版本(或者没有任何问题,正如评论所指出的)。您自己发布的代码似乎是正确的,但也许这个示例将帮助您解决真正的问题:

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)