# R语言与数据分析之二：绘图

１、直方图(hist())；２、散点图(plot())；３、柱状图(barplot());４、饼图(pie());５、箱线图(boxplot());６、星相图(stars());７、脸谱图(faces());８、茎叶图(stem());９、QQ图(qqnorm())；１０、 地图包maps、mapdata、geosphere

1. Num=seq(102001,102100)
2. X1=round(runif(100,min=80,max=100))
3. X2=round(rnorm(100,mean=80,sd=7))
4. X3=round(rnorm(100,mean=83,sd=18))

## 基本统计–单指标

1. X2[which(X2>100)]=100
2. X3[which(X3>100)]=100
3. X=data.frame(Num,X1,X2,X3)

1. hist(X\$X1)
2. plot(X1,X2)
3. barplot(table(X\$X1))
4. pie(table(X\$X1))

## 基本统计–多指标

1. boxplot(X\$X1, X\$X2, X\$X3)
2. boxplot(X[2:4],col=c("red","green","blue"),notch=T)

1. stars(X)
2. install.packages("TeachingDemos")
3. library("TeachingDemos")
4. faces2(X)

1. stem(X\$X2)

R语言还提供了判断数列是否服从正态分布的形象展示图形，可以简单的借助肉眼判断，当散落的点的分布越接近直线，则数列的分布越接近正态分布。命令如下：

1. qqnorm(X3)
2. qqline(X3)

## 地图专栏

1. library(maps)
2. map("world",fill=TRUE,col=rainbow(200),ylim=c(-60,90),mar=c(0,0,0,0))
1. library(mapdata)
2. map("china",col="red4",ylim=c(18,54),panel.first=grid())

3. map("world",col="#f2f2f2",fill=TRUE,bg="white",lwd=0.5)
4. fsub <- flights[flights\$airline==”AA”,]
5. for (j in 1:length(fsub\$airline)) {
6. air1 <- airports[airports\$iata == fsub[j,]\$airport1,]
7. air2 <- airports[airports\$iata == fsub[j,]\$airport2,]
8. inter <- gcIntermediate(c(air1[1,]\$long, air1[1,]\$lat), c(air2[1,]\$long, air2[1,]\$lat), n=100, addStartEnd=TRUE)
9. lines(inter, col="black", lwd=0.8)
10. }

http://blog.csdn.net/howardge/article/details/41598239

2119 篇文章135 人订阅

0 条评论

18430

59760

601110

49540

36360

9020

35440

35630

388160

21640