基本作图
library(datasets)
head(cars)
plot(cars)
plot(cars$dist,cars$speed,xlab = "dist", ylab = "speed",xlim = c(0,20))
attach(cars)
plot(dist,speed,xlab = "dist",ylab = "speed")
plot(cars$dist,cars$speed,xlab = "dist",ylab = "speed",main = "cars 散点图",type="b",pch=4,lwd=2,col="red")
a<-c(20,30,40,50,60)
b<-c(11,22,33,44,66)
c<-c(15,25,35,45,55)
plot(a,b,type = "b")#有点,用线连接
plot(a,b,type = "o")#有点,线连接,线过点
plot(a,b,type = "p")#点图
plot(a,b,type = "h")#用线表示值
plot(a,b,type = "l")#直接线链接
plot(a,b,type = "s")#梯形图
plot(a,b,type = "S")#梯形图
plot(a,b,type = "n")#不做图
plot(a,b,pch=0)
plot(a,b,pch=1)
plot(a,b,pch=2)
plot(a,b,pch=3)
plot(a,b,lty=2,lwd=2,pch=15,cex=2)
plot(a,b,type="b",lty=2,lwd=2,pch=15,cex=2)
install.packages("RColorBrewer")
library(RColorBrewer)
plot(a,b,type="b",lty=2,lwd=2,pch=15,cex=2,col=2)
opar<-par(no.readonly = FALSE)
par(pin=c(2,3))
par(lwd=2,cex=1.5)
par(cex.axis=.75,font.axis=3)
plot(a,b,type="b",pch=19,lty=2,col=2)
plot(a,b,type="b",pch=23,lty=5,col=2,bg="green")
par(opar)
par(mfrow = c(2, 2))
plot(a,c,type = "o",col=3,lty=3,pch=3,lwd=4,
main = "实验图形",xlab="a",ylab="c",
xlim = c(0,100),ylim=c(0,100))
x<-c(1:15)
y<-x
z<-10/x
opar<-par(no.readonly = TRUE)
par(mar=c(5,4,4,8)+0.1)
plot(x,y,type = "b",pch=21,col=2,yaxt="n",lty=3,ann = FALSE)
lines(x,z,type = "b",pch=3,col=4,lty=2)
axis(side = 2,at=x,labels = x,col.axis=2,las=2)
axis(side = 4,at=z,labels = round(z,digits = 2),
cex.axis=2,las=2)
par(opar)
library(datasets)#加载数据包
attenu#
attach(attenu)
subset(attenu,dist>=40)#选出dist列大于等于14的一行
df<-subset(attenu,event=="2" & dist=="107",select=c(dist));df#显示特定的行
s=subset(attenu,event=="2" & dist=="107",select=c(event,dist));s#多条件查询
df1<-as.list(attenu);df1#转换成列表
append(df1$event,123)#在event后部分追加123这个数
append(df1,1235,after = 55)#指定长度追加
data1= data.frame(Id=c(1:6),Product=c(rep("Toa