R语言学习笔记1:图形

a<-read.csv("C:/Users/panda/Desktop/train22.csv",sep=";")    #读取分隔符数据,sep按;分列
attach(mtcars)
plot(wt,mpg)                        #plot(type-直线类型,pch-绘点符号,cex-符号大小,lty-线条类型,lwd-线条宽度x = mtcars$wt,y = mtcars$mpg,type="o",线型main="标题",sub="子标题",xlab="x轴",ylab="y轴")
abline(lm(mpg~wt))                  #生成最佳拟合曲线
title("Regression of MPG on Weight")
detach(mtcars)


 一、图形

         (一)图形排布

par(mfrow=c(2,2))                #图形排列为2x2
hist()                 #hist为直方图包含默认标题,可用 main="" 禁用

 调节分布

attach(mtcars)
layout(matrix(c(1,1,2,3),2,2,byrow = TRUE))     #控制图形分布
hist(wt)
hist(mpg)
hist(disp)

   调节长宽占比

layout(matrix(c(1,1,2,3),2,2,byrow = TRUE),widths = c(3,1),heights = c(1,2))     #控制图形分布,调节长宽
hist(wt)
hist(mpg)
hist(disp)

(二)高级图形

opar<-par(no.readonly = TRUE)
par(fig=c(0,0.8,0,0.8))                     #fig(x1,x2,y1,y2)绘图区域,
plot(mtcars$wt,mtcars$mpg,xlab="Miles Per Gallon",ylab="Car Weight")  #散点图
par(fig=c(0,0.8,0.55,1),new=TRUE)              #fig默认新建一幅图,所以设定new=TRUE
boxplot(mtcars$wt,horizontal = TRUE,axes=FALSE)    #箱线图
par(fig=c(0.65,1,0,0.8),new=TRUE)
boxplot(mtcars$mpg,axes=FALSE)
mtext("标题",side=3,outer=TRUE,line=-3)
par(opar)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值