R语言基础包中的绘图函数——快速用R探索数据

library(ggplot2)

#R语言中的基础包所带的绘图函数虽然用起来相对ggplot2包不是那么友好
#但在刚拿到原始数据时进行快速探索还是很方便的


####散点图
#运用plot()函数,向函数传入一个x向量和一个y向量
plot(mtcars$wt,mtcars$mpg)
#等价于
qplot(wt,mpg,data = mtcars)
#等价于
ggplot(data = mtcars,mapping = aes(x = wt,y = mpg)) + geom_point()


####折线图
#同样运用plot()函数,向函数传入一个x向量和一个y向量,同时传入参数type = "l"
plot(pressure$temperature,pressure$pressure,type = "l")
#继续向图中添加数据点和折线
points(pressure$temperature,pressure$pressure)
lines(pressure$temperature,pressure$pressure/2,col = "red")
points(pressure$temperature,pressure$pressure/2,col = "red")
#等价于
qplot(pressure$temperature,pressure$pressure,geom = c("line","point"))
#等价于
ggplot(data = pressure,mapping = aes(x = temperature,y = pressure)) + geom_line() + geom_point()


####条形图
#使用barplot()函数,并向其传递两个向量作为参数,第一个向量用来设定条形的高度
#第二个向量用来设定每个条形对应的标签(可选)
barplot(BOD$demand,names.arg = BOD$Time)
#生成频数表
barplot(table(mtcars$cyl))
#qplot()绘制条形图
#qplot(factor(BOD$Time),BOD$demand,geom="bar",stat="identity")   这里stat参数有问题
#等价于
gg
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值