我已经陷入了问题:我需要绘制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()
Run Code Online (Sandbox Code Playgroud)
但是当我应用这个代码时,图像变得非常糟糕,它不能缩放(适合)所需的大小.我错过了什么?如何将图像"拟合"到情节中?
,
Ric*_*ton 59
一个可重复的例子:
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"
)
}
Run Code Online (Sandbox Code Playgroud)
詹姆斯建议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()
Run Code Online (Sandbox Code Playgroud)
当然,更好的解决方案是放弃使用基本图形的这种摆弄,并使用一个能够为您处理分辨率缩放的系统.例如,
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
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
96511 次 |
| 最近记录: |