我在Mac上运行此代码(OS X Yosemite 10.10.2)
par(bg = "transparent")
with(FilteredDates, plot(DateTime, Sub_metering_1, xlab=NA, ylab="Energy Sub metering",lty=1, lwd=1, pch=".", type="n"))
with(FilteredDates, lines(DateTime, Sub_metering_1,lty=1, lwd=1, pch="."))
with(FilteredDates, lines(DateTime, Sub_metering_2,lty=1, lwd=1, pch=".", col="red"))
with(FilteredDates, lines(DateTime, Sub_metering_3,lty=1, lwd=1, pch=".", col="blue"))
legend("topright", legend=c("Sub_metering_1","Sub_metering_2","Sub_metering_3"),cex=0.7, lty=1, col=c("black","red","blue"))
dev.copy(png, file="plot3.png", width=480,height=480, type="quartz")
dev.off()
因此,我需要一个方形 png 文件480x480。 默认的图形类型是" quartz"。
我做错了什么?
答案 0 :(得分:1)
您可以尝试手动设置text.width
的{{1}}参数。但是,它应自动默认为适当的长度,即legend
参数中最长字符串的长度。我怀疑这是使用legend
并明确指定宽度和高度的结果。
尝试使用以下命令直接绘制到PNG设备:
dev.copy