0

嗨,我正在尝试使用 RStudio 保存高质量(300 dpi)图像,但到目前为止还没有运气。我在互联网上看了很多,但似乎没有答案。即使我运行下面的代码,我的计算机上也没有显示任何文件。任何帮助表示赞赏!

install.packages("gapminder")
library(gapminder)
data("gapminder")

attach(gapminder)

plot(lifeExp ~ log(gdpPercap))
ggsave("filename.png",dpi = 300)
4

1 回答 1

0

如果你使用ggplot()fromggplot2而不是plot()

包和数据

library(ggplot2)
library(gapminder)

data("gapminder")
attach(gapminder)

解决方案

ggplot(gapminder,
       aes(x =  log(gdpPercap), y = lifeExp)) +
  geom_point()

ggsave("filename.png",dpi = 300)

以下是您进行的一些调整,以使其与 plot()外观更相似:

ggplot(gapminder,
       aes(x =  log(gdpPercap), y = lifeExp)) +
  geom_point(shape = 1) +
  theme_linedraw()

最后一个代码的输出

在此处输入图像描述

于 2022-02-24T04:23:39.990 回答