张金龙的博客分享 http://blog.sciencenet.cn/u/zjlcas 物种适应性、分布与进化

博文

R绘图一则 (2017年1月9日修订)

已有 15242 次阅读 2012-10-11 01:33 |个人分类:统计分析|系统分类:科研笔记|关键词:学者| white, initial

R绘图一则

(2017年1月9日修订)

张金龙

jinlongzhang01@gmail.com

这里给出R常见绘图用到的参数。供生成出版质量的TIFF图。


调整R绘图的字体,一页多图, 分辨率600dpi tiff 压缩方式lzw

tiff(filename = "test.tif",

    width = 3600, height = 3600, units = "px", pointsize = 8,

    compression = "lzw", res = 600) ## 打开绘图器

par(mfrow = c(2,2), font.lab = 6, font.main = 6,font.axis = 6, font = 6) ## 分割成22列,共四个图

## 1

## 标题部分斜体

hist(rnorm(200), main = expression(paste("Testing ", italic(Hist1))), col = "gray")

# 添加边框

box()

## 图中添加图例

legend.label <- c("Type I", "Type II", "Type III")

legend(1.5, 30, legend = legend.label, pch = c(19, 20, 21), col = c(1, 2, 3))

legend(-3.0, 30, legend = legend.label, lty = c(1, 2, 3), col = c(1, 2, 3))

   

## 2

## 标题中显示度等特殊字符,标题中显示希腊字母

hist(rnorm(200), main = expression(paste(plain(sin) * phi, "  and ", plain(cos) * phi)), xlab = expression(paste("Latitude ", degree)), col = "gray")

## 图中添加公式

text(-2, 30, expression(bar(x) == sum(frac(x[i], n), i==1, n)), cex = 1.2)

## 3

x <- rnorm(100)

m=mean(x)

sd=sd(x)

hist(x)

x00 <- seq(-10, 10, 0.01)

lines(x00, m*dnorm(x00,m,sd), lty=1, col="red")

### 4

y = 1:50 + (5*rnorm(50) + 20)

x = 1:50

plot(y ~ x, main = "Scatter plot", col = "gray")

abline(lm(y ~ x), col = 2)

dev.off() ## 关闭绘图器

getwd()   ## 查看图保存的位置

保存多个矢量图到一个pdf文件


pdf(file = "test.pdf", width = 6, height = 6, pointsize = 12, onefile = TRUE)

plot(rnorm(1:10), rnorm(1:10), col = 1:10, main = "plot1") ### plot1

plot(rnorm(1:10), rnorm(1:10), col = 1:10, main = "plot2") ### plot2

dev.off()

getwd()




https://m.sciencenet.cn/blog-255662-621286.html

上一篇:LyX生成中文pdf文档
下一篇:两棵进化树一致性的校对

1 夏少波

该博文允许注册用户评论 请点击登录 评论 (4 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-4-18 23:16

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部