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") # 对比图

在这里插入图片描述

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值