R语言绘制散点图和直方图

绘制简单散点图
在这里插入图片描述
用ggplot绘制散点图

library(ggplot2)
qplot(mtcars$wt, mtcars$mpg)

在这里插入图片描述
带有标注的散点图

qplot(wt, mpg, data=mtcars)
ggplot(mtcars, aes(x=wt, y=mpg)) + geom_point()

在这里插入图片描述
绘制竖桩图

barplot(BOD$demand, names.arg=BOD$Time)

在这里插入图片描述

table(mtcars$cyl)
barplot(table(mtcars$cyl))

在这里插入图片描述

qplot(Time, demand, data=BOD, geom="bar", stat="identity")

# This is equivalent to:

ggplot(BOD, aes(x=Time, y=demand)) + geom_bar(stat="identity")

# Bar graph of counts

qplot(factor(cyl), data=mtcars)

# This is equivalent to:

ggplot(mtcars, aes(x=factor(cyl))) + geom_bar()

在这里插入图片描述

hist(mtcars$mpg)

在这里插入图片描述

hist(mtcars$mpg, breaks=10)

在这里插入图片描述
R Graphics Cookbook----O’REILLY—[美]Winston Chang

开发环境:RStudio 4.2.0


版权声明:本文为m0_38127487原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。