# R语言简单绘图（二）

1、条形图—barplot()

barplot(c(1,2,4,2,6,4,3,5))
barplot(c(1,2,4,2,6,4,3,5), horiz = TRUE)

counts = table(Arthritis$Improved) barplot(counts, horiz = TRUE) counts = table(Arthritis$Improved, Arthritis$Treatment) barplot(counts, beside = TRUE) state <- data.frame(state.region, state.x77) x <- aggregate(state$Illiteracy, by=list(state.region), FUN=mean)
barplot(x$x, names.arg =x$Group.1)

par(mar=c(5,8,4,2))
counts <- table(Arthritis$Improved) barplot(counts, horiz = TRUE, cex.names = 0.8, names.arg = c("no improved", "some", "marked")) par(las=2) barplot(counts, horiz = TRUE, cex.names = 0.8, names.arg = c("no improved", "some", "marked")) 2、饼图—pie() par(mfrow=c(2,2)) x <- c(10,12, 4,16, 8) lab <- c("US", "UK", "Australia", "Germany", "France") pie(x, lab, main="Simple Pie Chart") pct <- round(x/sum(x)*100) lab1 <- paste(lab, " ", pct, "%", sep = " ") pie(x,lab1, col = rainbow(length(lab1)), main = "Pie Chart with Percentage") pie3D(x, explode=0.1, main="3D Pie Chart") fan.plot(x, labels = lab, main="Fan Plot") # 扇形图 3、直方图—hist() attach(mtcars) # 导入数据 x <- mtcars$mpg
hist(x)

hist(x,breaks = 12, col="red",xlab = "Miles Per Callon")

hist(x, freq = FALSE, breaks = 12, col = "green",xlab = "Miles Per Callon")
lines(density(x), col="red", lwd=2)

4、箱线图

boxplot(mtcars\$mpg, mian="Box plot", ylab="Mile per gallon")

boxplot(mpg~cyl, data=mtcars, main="Car mileage data", xlab="Number of cylinders", ylab="Miles per gallon") # 对比图

• 点赞
• 评论
• 分享
x

海报分享

扫一扫，分享海报

• 收藏
• 手机看

分享到微信朋友圈

x

扫一扫，手机阅读

• 打赏

打赏

开开_王子

你的鼓励将是我创作的最大动力

C币 余额
2C币 4C币 6C币 10C币 20C币 50C币
• 一键三连

点赞Mark关注该博主, 随时了解TA的最新博文
07-26
06-25 1万+

02-25 1万+
05-07 3716
11-29 4万+
10-06 2万+
02-14 1597
05-25 2万+