1.图像语法
2.基础
- 引入ggplot2
> library(ggplot2)
- 数据集介绍
> help(mtcars)
字段描述
A data frame with 32 observations on 11 variables.
[, 1] mpg Miles/(US) gallon
[, 2] cyl Number of cylinders
[, 3] disp Displacement (cu.in.)
[, 4] hp Gross horsepower
[, 5] drat Rear axle ratio
[, 6] wt Weight (1000 lbs)
[, 7] qsec 1/4 mile time
[, 8] vs V/S
[, 9] am Transmission (0 = automatic, 1 = manual)
[,10] gear Number of forward gears
[,11] carb Number of carburetors
3.简单示例
- 重量与单位里程关系
> ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point()
- 重量与单位里程关系(根据排气量设定颜色)
> ggplot(mtcars, aes(x = wt, y = mpg, color = disp)) +
geom_point()
- 重量与单位里程关系(根据排气量设定点的尺寸)
ggplot(mtcars, aes(x = wt, y = mpg, size = disp)) +
geom_point()
3.各类图像
- 频率分布直方图(histogram)