目录
-
-
-
- 绘图数据
- 多图设置
- 各种图
-
-
- 直方图
- 条形图
- 散点图
- 饼状图
- 箱型图
- 星图
- 脸谱图
- 茎叶图
- qqplot
- 热图
- 太阳花图
- 散点图矩阵
- 三维散点图
- 等高线图
- 地图
绘图数据
x1 = round(runif(100,80,100))
x2 = round(rnorm(100,80,7))
x3 = round(rnorm(100,83,18))
x3[which(x3>100)] = 100
num = seq(1,100)
x = data.frame(num,x1,x2,x3)
多图设置
#par
par(mfrow = c(2,2))
plot(rnorm(60),pch = 17)
plot(rnorm(60),type = "l",lty = 5)
plot(rnorm(60),cex = 0.5)
plot(rnorm(60),lwd = 2)
#layout
layout(matrix(c(1,1,2,3),2,2,byrow = T))
plot(rnorm(60),pch = 17)
plot(rnorm(60),type = "l",lty = 5)
plot(rnorm(60),cex = 0.5)
各种图
直方图
hist(x$x1)
条形图
barplot(table(x$x1))
散点图
plot(x$x1,x$x2)
plot(c(2,3,4,5),c(2,3,5,8),type = 'l',col = "red")
lines(c(2,3,4,5),c(1,4,6,9),type = 'l',col = "blue")
plot(x$x1,x$x2,
main = "title",
xlab = "xlab",
ylab = "ylab",
xlim = c(60,100),
ylim = c(60,100),
xaxs = "i",
yaxs = "i",
col = "red",
pch = 19)
饼状图
pie(table(x$x1))
箱型图
boxplot(x$x1,x$x2,x$x3)
boxplot(x[2:4],col = c("red","green","blue"),notch = T)
boxplot(x[2:4],horizontal = T)
星图
stars(x[2:4])
stars(x[2:4],full = T,draw.segments = T)
stars(x[2:4],full = F,draw.segments = T)
脸谱图
library(aplpack)
faces(x[2:4])
library(TeachingDemos)
faces2(x[2:4])
茎叶图
stem(x$x2)
qqplot
qqnorm(x1)
qqline(x1)
热图
heatmap(as.matrix(x[2:4]),
Rowv = NA,
Colv = NA,
col = heat.colors(256),
scale = "column",
margins = c(2,8),
main = "title")
太阳花图
sunflowerplot(x[2:4],col = "gold",seg.col = "gold")
散点图矩阵
pairs(x[2:4])
三维散点图
library(scatterplot3d)
scatterplot3d(x[2:4])
等高线图
x <- y <- seq(-2*pi,2*pi,pi/15)
f <- function(x,y)
sin(x)*sin(y)
z <- outer(x,y,f)
contour(x,y,z,col = "blue")
persp(x,y,z,theta = 30,phi = 30,expand = 0.7,col = "lightblue")
地图
library(maps)
map("state",interior = F)
map("state",boundary = F,col = 'red',add = T)
map("world",fill = T,col = heat.colors(10))
map("world",
col = "#f2f2f2",
fill = T,
bg = "white",
lwd = 0.05,
xlim = c(-171.738281,-56.601563),
ylim = c(12.039321,71.856229))