【问题标题】:Save the plots as JPEG or PDF from jupyter notebook with R Kernel使用 R 内核将 jupyter notebook 中的绘图保存为 JPEG 或 PDF
【发布时间】:2020-02-07 06:21:24
【问题描述】:

我无法从 Jupyter Notebook 的 R 内核将绘图保存为 jpeg 或 pdf 格式。

这是代码,

pdf("Hatdog.jpeg")
plot(x,y, col="green")
dev.off() 

我想知道为什么图像已损坏,当我尝试打开实际文件时,它指出 看起来我们不支持这种文件格式。

有人遇到同样的问题吗?你是怎么解决的?谢谢。

【问题讨论】:

    标签: r jupyter-notebook jupyter-irkernel


    【解决方案1】:

    您正在保存扩展名为 -.jpg 的 pdf 文件? 保存为 jpeg:

    # 1. Open jpeg file
    jpeg("rplot.jpg", width = 350, height = 350)
    # 2. Create the plot
    plot(x = my_data$wt, y = my_data$mpg,
         pch = 16, frame = FALSE,
         xlab = "wt", ylab = "mpg", col = "#2E9FDF")
    # 3. Close the file
    dev.off()
    

    保存为 pdf:

    # Open a pdf file
    pdf("rplot.pdf") 
    # 2. Create a plot
    plot(x = my_data$wt, y = my_data$mpg,
         pch = 16, frame = FALSE,
         xlab = "wt", ylab = "mpg", col = "#2E9FDF")
    # Close the pdf file
    dev.off() 
    

    (来自http://www.sthda.com/english/wiki/creating-and-saving-graphs-r-base-graphs

    【讨论】:

    • 没有解决问题,当我打开文件时,提示we can't open this file。注意,我的操作系统是 windows 10。
    • 在您的第一行未注释的行中,高度 350 不应该在“”中,对吗?
    猜你喜欢
    • 1970-01-01
    • 2015-10-27
    • 2018-01-10
    • 1970-01-01
    • 2016-08-05
    • 1970-01-01
    • 2018-01-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多