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
R语言基础包中的绘图函数——快速用R探索数据
于 2018-12-17 10:21:45 首次发布