创建数据
num=seq(10378001,10378100)
x1=round(runif(100,min=80,max=100))
x2=round(rnorm(100,mean=80,sd=7))
x3=round(rnorm(100,mean=83,sd=18))
x3[which(x3>100)]=100
x=data.frame(num,x1,x2,x3)
作图
dev.new()
dev.set(dev.next())
hist(x$x1)
dev.off()
dev.new()
dev.set(dev.next())
plot(x$x1,x$x2)
dev.off()
dev.new()
dev.set(dev.next())
barplot(table(x$x1))
dev.off()
dev.new()
dev.set(dev.next())
pie(table(x$x1))
dev.off()
dev.new()
dev.set(dev.next())
boxplot(x$x1,x$x2,x$x3)
dev.off()
dev.new()
dev.set(dev.next())
boxplot(x[2:4],col=c("red","green","blue"),notch=T)
dev.off()
dev.new()
dev.set(dev.next())
boxplot(x$x1,x$x2,x$x3,horizontal=T)
dev.off()
dev.new()
dev.set(dev.next())
stars(x[c("x1","x2","x3")])
dev.off()
dev.new()
dev.set(dev.next())
stars(x[c("x1","x2","x3")],full=T,draw.segment=T)
dev.off()
dev.new()
dev.set(dev.next())
library("aplpack")
faces(x[c("x1","x2","x3")])
dev.off()
dev.new()
dev.set(dev.next())
library(TeachingDemos)
faces(x)
dev.off()
stem(x$x1)
dev.new()
dev.set(dev.next())
qqnorm(x1)
qqline(x1)
dev.off()
dev.new()
dev.set(dev.next())
plot(x$x1,
x$x2,
main="Relation between Mathematical Analysis and Linear Algebra Achievements",
xlab="Mathematical Analysis",
ylab="Linear Algebra",
xlim=c(70,110),
ylim=c(50,110),
xaxs="i",
yaxs="i",
col="red",
pch=19)
dev.off()
dev.new()
dev.set(dev.next())
a=c(2,3,4,5,6)
b=c(4,7,8,9,12)
plot(a,b,type="l")
dev.off()
dev.new()
dev.set(dev.next())
a=c(2,3,4,5,6)
b=c(4,7,8,9,12)
plot(a,b,type="l")
lines(c(10,10,10,10,10,10),type="l",col="red",lwd=2)
lines(c(4,4,4,4,4,4),type="l",col="green",lwd=2)
dev.off()
dev.new()
dev.set(dev.next())
plot(density(x2))
dev.off()
dev.new()
dev.set(dev.next())
heatmap(as.matrix(mtcars),
Rowv=NA,
Colv=NA,
col=heat.colors(256),
scale="column",
margins=c(2,8),
main="Car characteristics by Model")
dev.off()
dev.new()
dev.set(dev.next())
sunflowerplot(iris[, 3:4], col="gold", seg.col="gold")
dev.off()
dev.new()
dev.set(dev.next())
pairs(iris[,1:4])
dev.off()
dev.new()
dev.set(dev.next())
plot(iris[,1:4],
main="Relationships between
characteristics of iris flowers",
pch=19,
col="blue",
cex=0.9)
dev.off()
dev.new()
dev.set(dev.next())
par(mfrow=c(3,1))
plot(x1,x2);plot(x2,x3);plot(x3,x1)
dev.off()
dev.new()
dev.set(dev.next())
library(scatterplot3d)
scatterplot3d(x[2:4])
dev.off()
dev.new()
dev.set(dev.next())
x<-y<-seq(-2*pi, 2*pi, pi/15)
f<-function(x,y) sin(x)*sin(y)
z<-outer(x, y, f)
print(str(z))
contour(x,y,z,col="blue")
persp(x,y,z,theta=30, phi=30,
expand=0.7,col="lightblue")
dev.off()
dev.new()
dev.set(dev.next())
library(maps)
#map("state", interior = FALSE)
#map("state", boundary = FALSE, col="red",add = TRUE)
map('world', fill = TRUE,col=heat.colors(10))
dev.off()
dev.new()
dev.set(dev.next())
library(maps)
library(geosphere)
xlim <- c(-171.738281, -56.601563)
ylim <- c(12.039321, 71.856229)
map("world", col="#f2f2f2",
fill=TRUE, bg="white",
lwd=0.05, xlim=xlim,
ylim=ylim)
lat_ca <- 39.164141
lon_ca <- -121.64062
lat_me <- 45.21300
lon_me <- -68.906250
inter <- gcIntermediate(c(lon_ca, lat_ca),
c(lon_me, lat_me), n=50,
addStartEnd=TRUE)
lines(inter)
lat_tx <- 29.954935
lon_tx <- -98.701172
inter2 <-
gcIntermediate(c(lon_ca
, lat_ca), c(lon_tx, lat_tx),
n=50,
addStartEnd=TRUE)
lines(inter2, col="red")
dev.off()
dev.new()
dev.set(dev.next())
library(maps)
library(geosphere)
airports <- read.csv("http://datasets.flowingdata.com/tuts/maparcs/airports.csv",
header=TRUE)
flights <- read.csv("http://datasets.flowingdata.com/tuts/maparcs/flights.csv",
header=TRUE, as.is=TRUE)
map("world", col="#f2f2f2",
fill=TRUE,
bg="white",
lwd=0.05,
xlim=xlim,
ylim=ylim)
fsub <- flights[flights$airline == "AA",]
for (j in 1:length(fsub$airline)) {
air1 <- airports[airports$iata == fsub[j,]$airport1,]
air2 <- airports[airports$iata == fsub[j,]$airport2,]
inter <- gcIntermediate(c(air1[1,]$long,
air1[1,]$lat),
c(air2[1,]$long, air2[1,]$lat),
n=100,
addStartEnd=TRUE)
lines(inter, col="black", lwd=0.8)
}
dev.off()