如何改变Jupyter中R图的大小?

Jay*_*ong 16 plot r jupyter jupyter-notebook

我想知道如何配置Jupyter在R内核中绘制一个较小的数字.

我尝试过使用options(repr.plot.width = 1, repr.plot.height = 0.75, repr.plot.res = 300),但结果有点混乱.它正在改变产生的图R的大小.有没有什么办法可以在Jupyter中直接配置输出图形大小.

换句话说,如何将第一个图中的大小更改为第二个图中的大小,同时不会弄乱图.

在此输入图像描述 在此输入图像描述

小智 7

您需要手动设置刻度大小,标记大小和文本大小。文字大小和刻度大小可以通过theme()功能设置,而标记大小可以通过geom_point()功能设置。

df_1 = data.frame(x=c(5, 6, 7, 8, 9), y = c(200, 225, 250, 270, 310))

options(repr.plot.width = 1, repr.plot.height = 0.75)
ggplot(df_1, aes(x = x, y = y)) + geom_point(size = 0.3) + 
   theme(text = element_text(size = 3), element_line(size = 0.1))
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明


Car*_*lli 5

您应该简单地更改绘图的分辨率。例如,尝试repr.plot.res = 100

options(repr.plot.width = 1, repr.plot.height = 0.75, repr.plot.res = 100)
Run Code Online (Sandbox Code Playgroud)

  • 在 Colab 上使用它会给出错误“无效图形状态”,它无法使用“dev.off()”恢复,我必须重新启动运行时。 (6认同)
  • @Leonidas 避免将 `width` 或 `height` 设置为 1。当使用 `~1.85` 或更高版本时,我没有看到 `plot without title` 错误。 (2认同)