将多个 glm 图导出为 PNG?
所以,
我正在尝试导出线性模型的图。当我将其制作为 PDF 时,PDF 有四页和四个不同的图表。当我导出为 PNG 时,我只得到第一个图表。如何导出以便将所有四个图表作为单独的 PNG 文件获取?
什么适用于 PDF:
lrfitX11SUMS <- glm(X11SUMS ~ POLITA + CIRCULATION + COMPAPER + TrafficRankUS, data=NewspTest)
summary(lrfitOTONE)
pdf("/Users/william/Desktop/output/lmfitOTONE1.pdf")
plot(lrfitOTONE)
dev.off()
什么不适用于 PNG(花了两个小时在互联网和绘图文档中进行挖掘,但无济于事):
lrfitX11SUMS <- glm(X11SUMS ~ POLITA + CIRCULATION + COMPAPER + TrafficRankUS, data=NewspTest)
summary(lrfitOTONE)
png("/Users/william/Desktop/output/lmfitOTONE1.png", width=720, height=720, pointsize=16)
png("/Users/william/Desktop/output/lmfitOTONE2.png", width=720, height=720, pointsize=16)
png("/Users/william/Desktop/output/lmfitOTONE3.png", width=720, height=720, pointsize=16)
png("/Users/william/Desktop/output/lmfitOTONE4.png", width=720, height=720, pointsize=16)
plot(lrfitOTONE)
dev.off()
如何获取我的图像?
谢谢,
-Wm
SO,
I'm trying to export plots of my linear model. When I do it as a PDF, the PDF has four pages and four different charts. When I export as a PNG, I only get the first chart. How do I export so that I get all four graphs as separate PNG files?
What worked with the PDF:
lrfitX11SUMS <- glm(X11SUMS ~ POLITA + CIRCULATION + COMPAPER + TrafficRankUS, data=NewspTest)
summary(lrfitOTONE)
pdf("/Users/william/Desktop/output/lmfitOTONE1.pdf")
plot(lrfitOTONE)
dev.off()
What DIDN'T WORK with PNG (and spent two hours digging around on the internet and in the plot documentation to no avail):
lrfitX11SUMS <- glm(X11SUMS ~ POLITA + CIRCULATION + COMPAPER + TrafficRankUS, data=NewspTest)
summary(lrfitOTONE)
png("/Users/william/Desktop/output/lmfitOTONE1.png", width=720, height=720, pointsize=16)
png("/Users/william/Desktop/output/lmfitOTONE2.png", width=720, height=720, pointsize=16)
png("/Users/william/Desktop/output/lmfitOTONE3.png", width=720, height=720, pointsize=16)
png("/Users/william/Desktop/output/lmfitOTONE4.png", width=720, height=720, pointsize=16)
plot(lrfitOTONE)
dev.off()
How do I get my images?
Thanks,
-Wm
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
PDF 允许多页文档。 PNG 图像从根本上与这个想法不兼容。阅读
?png
并意识到需要查看filename
参数,将会引导您前往?postscript
了解详细信息。您想要类似的内容:
其中文件名中的
%1d
是一个通配符,它扩展为 1 位数字值,这样您就可以得到带有您想要的名称的四个数字。您对png()
的 4 次调用设置了四个单独的设备,只有后者被使用并随后关闭,其他三个保持打开状态。A PDF allows multipage documents. A PNG image is fundamentally incompatible with this idea. Reading
?png
and appreciating the need to look at thefilename
argument would have directed you to?postscript
for the details.You want something like:
where the
%1d
in the filename is a wildcard that expands to a 1 digit numeric value such that you get four figures with the names you wanted. Your 4 calls topng()
set up four separate devices, only the latter of which was used and subsequently closed, the other three remained open.像这样的事情:
关键是实现
plot.lm
(这是plot
使用的方法应用于glm
对象,因为glm
是lm
的子类,没有自己特定的绘图方法)根据which
参数显示诊断图,默认值为which
与wplot
相同 多于。所以基本上:弄清楚如何创建各个子图。Something like this:
The key is realizing that
plot.lm
(which is the method used byplot
applied to aglm
object, becauseglm
is a subclass oflm
and doesn't have its own particular plot method) displays diagnostic plots based on thewhich
argument, and the default value ofwhich
is the same aswplot
above. So basically: figure out how to create the individual sub-plots.