【问题标题】:How to change the size of R plots in Jupyter?如何更改 Jupyter 中 R 图的大小?
【发布时间】:2017-08-01 10:15:58
【问题描述】:

我想知道如何配置 Jupyter 以在 R 内核中绘制一个较小的图形。

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

换句话说,我怎样才能将第一个图中的大小更改为第二个图中的大小,同时又不会弄乱情节。

【问题讨论】:

    标签: r plot jupyter-notebook jupyter


    【解决方案1】:

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

    options(repr.plot.width = 1, repr.plot.height = 0.75, repr.plot.res = 100)
    

    【讨论】:

    • 在 Colab 上使用它会给出错误 invalid graphics state,它无法使用 dev.off() 恢复,我必须重新启动运行时。
    【解决方案2】:

    您需要手动设置刻度大小、标记大小和文本大小。文本大小和刻度大小可以通过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))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-06
      • 2018-10-28
      • 1970-01-01
      • 2012-10-14
      • 1970-01-01
      • 2021-04-17
      • 2021-05-03
      • 1970-01-01
      相关资源
      最近更新 更多