R的学习——chap.3图形初阶

图形初阶

3.1 使用图形

在交互对话中,通过逐条语句构建图形,例如:

attach(mtcars)
plot(wt, mpg)
abline(lm(mpg~wt))
title("Regression of MPG on Weight")
detach(mtcars)

通过图形用户界面保存图形,或者通过代码保存图形到当前工作目录,例如:

#保存绘制的图形到当前工作目录
#attach()将数据框添加到搜索路径中;detach()将数据框从搜索路径中移除
pdf("mygraph.pdf")
 attach(mtcars)
 plot(wt, mpg)
 abline(lm(mpg~wt))
 title("Regression of MPG on Weight")
 detach(mtcars)
dev.off()

创建多个图形并随时查看每一个图形,方法有三:1)创建新图形之前打开一个新的图形窗口. 

2)通过图形界面查看多个图形(Mac中是command+⬅️/command+➡️) 

3)使用函数dev.new()、dev.next()、dev.prev()、dev.set()和dev.off()同时打开多个图形窗口,并选择将哪个输出发送到哪个窗口。(详情参考help(dev.cur)

3.2 图形参数

使用par()函数。

example:

# Input data for drug example
dose  <- c(20, 30, 40, 45, 60)
drugA <- c(16, 20, 27, 40, 60)
drugB <- c(15, 18, 25, 31, 40)
plot(dose, drugA, type="b")

#图形参数
opar <- par(no.readonly=TRUE) 
# make a copy of current settings
par(lty=2, pch=17)            
# change line type and symbol
plot(dose, drugA, type="b")   
# generate a plot
par(opar)                     
# restore the original settings 



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值