我已经陷入了这个问题:我需要使用 DPI=1200 和特定的打印尺寸来绘制图像。
默认情况下 png 看起来不错...
png("test.png",width=3.25,height=3.25,units="in",res=1200)
par(mar=c(5,5,2,2),xaxs = "i",yaxs = "i",cex.axis=1.3,cex.lab=1.4)
plot(perf,avg="vertical",spread.estimate="stddev",col="black",lty=3, lwd=3)
dev.off()
但是当我应用此代码时,图像变得非常糟糕,它没有缩放(适合)到所需的尺寸。我错过了什么?如何使图像“适合”情节?
,
最佳答案
可重现的示例:
the_plot <- function()
{
x <- seq(0, 1, length.out = 100)
y <- pbeta(x, 1, 10)
plot(
x,
y,
xlab = "False Positive Rate",
ylab = "Average true positive rate",
type = "l"
)
}
James 建议使用 pointsize
并结合各种 cex
参数,可以产生合理的结果。
png(
"test.png",
width = 3.25,
height = 3.25,
units = "in",
res = 1200,
pointsize = 4
)
par(
mar = c(5, 5, 2, 2),
xaxs = "i",
yaxs = "i",
cex.axis = 2,
cex.lab = 2
)
the_plot()
dev.off()
<小时/>
当然,更好的解决方案是放弃这种对基本图形的摆弄,并使用可以为您处理分辨率缩放的系统。例如,
library(ggplot2)
ggplot_alternative <- function()
{
the_data <- data.frame(
x <- seq(0, 1, length.out = 100),
y = pbeta(x, 1, 10)
)
ggplot(the_data, aes(x, y)) +
geom_line() +
xlab("False Positive Rate") +
ylab("Average true positive rate") +
coord_cartesian(0:1, 0:1)
}
ggsave(
"ggtest.png",
ggplot_alternative(),
width = 3.25,
height = 3.25,
dpi = 1200
)
关于R图: size and resolution,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8399100/