我正在Mac上运行这段代码( 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。默认的图形类型是“石英”。
但我的传说不适合这个盒子:
我做错什么了?
发布于 2015-03-18 19:23:29
您可以尝试手动设置text.width
参数的legend
。但是,它应该自动默认为适当的长度,即legend
参数中最长字符串的长度。我怀疑这是使用dev.copy
并在其中显式地指定宽度和高度的结果。
使用以下命令尝试直接绘图到PNG设备:
png("plot3b.png", width=480, height=480, type="quartz")
par(bg = "transparent")
plot(DateTime, Sub_metering_1, xlab=NA, ylab="Energy Sub metering",lty=1, lwd=1, pch=".", type="n")
lines(DateTime, Sub_metering_1, lty=1, lwd=1, pch=".")
lines(DateTime, Sub_metering_2, lty=1, lwd=1, pch=".", col="red")
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.off()
https://stackoverflow.com/questions/29124672
复制相似问题