[R] size_in_fig

R中保存pdf文档的两种方法:

  1. pdf+dev.off()
pdf(file = if(onefile) "Rplots.pdf" else "Rplot%03d.pdf",
    width, height, onefile, family, title, fonts, version,
    paper, encoding, bg, fg, pointsize, pagecentre, colormodel,
    useDingbats, useKerning, fillOddEven, compress)

其中,参数width和height的默认单位为英寸,要以cm为单位需要进行转换

# Create a 8 cm* 8 cm  file
pdf(<outfile>,width=8/2.54,height=8/2.54)
print(ggplot(...))  #支持print函数
dev.off()
  1. ggsave()
ggsave(filename, plot = last_plot(), device = NULL, path = NULL,
  scale = 1, width = NA, height = NA, units = c("in", "cm", "mm"),
  dpi = 300, limitsize = TRUE, ...)
#指定单位
ggsave(filename, width=8, height = 8, unit='cm')
#不需要手动关闭图形设备

输出png文件

#png指定的width和height单位为像素
png(filename,width=400,height=400)
...
dev.off()
#或ggsave
ggsave(filename,width=8,height=8,unit='cm',dpi=300)

关于dpi的说明:

分辨率,实际上控制的是 像素/英寸 (pixels per inch, ppi)

Linux下pdf转png

convert -units PixelsPerInch -density 300 <pdf file> <png file>

参数说明: convert parameters
-density geometry horizontal and vertical density of the image
-units type the units of image resolution
-monochrome transform image to black and white (黑白色)
-negate replace each pixel with its complementary color (反色)
-resize geometry resize the image,eg. 50% or 1024 X 1024 (单位为像素,中间字符为X)
-pointsize value font point size

参考网站:

字体相关

install.packages('extrafont')
library('extrafont')
#查找并保存系统中已安装的字体
font_import()
#列出字体
fonts()
#ggplot中关于字体的设置
text= element_text(size = 16,family = "Impact")
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 8,084评论 0赞 10
  • 您好,您的当前可用2016年余额2天,欢迎您即将进入2017年! 在这个鸡年即将来临的时刻,我们是不是要囤一些“鸡...
    0a911c2e79ad阅读 203评论 0赞 0
  • 序 胡适说“你的闲暇往往定了你的终身”,穷忙——在网络社交工具兴起的同时诞生的...
    安飞驼阅读 676评论 0赞 0
  • 塞外牙旗風繞,玉門蕭鼓雲浮。無限煙沙連醉醒,萬裏關河夢去留,凝眸黯未收。 �已是紅疏翠密,何曾草綠花柔。一曲客聽江...
    圓月阅读 269评论 8赞 2
  • 公交车上,看见一位小女生坐在他爸爸的腿上,且他爸爸手里还拿着一个红色塑料袋,偶尔间还能听见小女生发出“呕~...
    小Lila阅读 554评论 6赞 4

友情链接更多精彩内容