2011-12-12 105 views
2

我不明白我如何安排一个绘图来填充特定像素大小的图像,具有特定的字体大小和小的边距。下面是一个例子情节:了解PNG输出设置

library(ggplot2) 

a <-c(1:10); b <- c(1:10) 
p <- qplot(a,b) 
outPath = "D:/Scratch/" 

# 1 
png(paste(outPath, '1.png', sep=''), height=400, width=400, res = 120, units = 'px') 
print(p); dev.off() 

enter image description here

# 2 
png(paste(outPath, '2.png', sep=''), pointsize = 20,height=400, width=400, res = 120, units = 'px') 
print(p); dev.off() 

enter image description here

# 3 
png(paste(outPath, '3.png', sep=''), height=400, width=400, res = 250, units = 'px') 
print(p); dev.off() 

enter image description here

我不太关注图像的分辨率,但我想要的字体大小与整体图像成比例(与图3相似)。参数pointsize似乎不会导致任何字体大小changes.I还希望边框被最小化。目前,如果我使用#3上的设置,则与其他图像相比,情节周围会有更大的空间。我怎么能有一个大字体的情节,有一个小保证金?

+0

我总是用ggsave保存,就像一个魅力。 –

+0

也许我应该用不同的软件包来说明我的问题。我使用'rasterVis'生成空间数据图,但我认为一般问题可能相似,并且'ggplot'更易于解释问题。我现在意识到它是更具体的包。 – djq

回答

2

ggplot2侧(与使用png()设置进行比较),控制保存图像的大部分方面将更容易完成。

ggplot2,opts()可以用来控制字体大小和图边距的宽度。

下面是一个例子:

p <- qplot(a,b) + 
opts(plot.margin = unit(rep(0,4), "lines"), 
    axis.title.x = theme_text(size=20), 
    axis.title.y = theme_text(size=20)) 

png('1.png', height=400, width=400, res = 120, units = 'px') 
print(p); dev.off() 

enter image description here