1.圖像語法
Paste_Image.png
ggplot2分層概念
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()
重量wt與單位里程mpg關系
- 重量與單位里程關系(根據排氣量設定顏色)
> ggplot(mtcars, aes(x = wt, y = mpg, color = disp)) +
geom_point()
重量wt與單位里程mpg關系
- 重量與單位里程關系(根據排氣量設定點的尺寸)
ggplot(mtcars, aes(x = wt, y = mpg, size = disp)) +
geom_point()
重量wt與單位里程mpg關系
Paste_Image.png
3.各類圖像
- 頻率分布直方圖(histogram)