首页 > 解决方案 > R绘图不保存为png,请检查我的代码

问题描述

我已经为正确的绘图编写了代码,但我无法将其保存为 png 文件。我在绘制之前使用了 png() 函数,之后使用了 dev.off() 并且它不会保存。顺便说一句,我没有包括读取数据和创建变量。(苹果电脑)

我已经尝试了一切,没有任何效果。有没有办法保存全图?

png(filename = "plot_3.png", width = 480, height = 480)

p1 <- (ggplot(PTsum, aes(x=Group.1, y =x))
              + geom_bar(stat="identity", color="black"
                     , fill="gray") + ggtitle("Point") + 
xlab("Date") + ylab("Total Emission"))
p2 <- (ggplot(NPTsum, aes(x=Group.1, y =x))
              + geom_bar(stat="identity", color="black"
                         , fill="gray") + ggtitle("NonPoint") + 
xlab("Date") + ylab("Total Emission"))
p3 <- (ggplot(Rsum, aes(x=Group.1, y =x))
              + geom_bar(stat="identity", color="black"
                     , fill="gray") + ggtitle("Road") + 
xlab("Date") + ylab("Total Emission"))
p4 <- (ggplot(NRsum, aes(x=Group.1, y =x))
              + geom_bar(stat="identity", color="black"
                     , fill="gray") + ggtitle("NonRoad") + 
xlab("Date") + ylab("Total Emission"))
fullplot <- multiplot(p1,p2,p3,p4,cols=2)

dev.off()

我希望有一个名为 plot3.png 的文件,但它不存在

标签: r

解决方案


推荐阅读