library(ggplot2) ##須先安裝 install.packages("ggplot2")
mpg <- mpg
# variable  detail
# manufacturer  車廠
# model 型號
# displ 引擎排氣量
# year  出廠年份
# cyl   氣缸數
# trans 自/手排
# drv   f = front-wheel drive, r = rear wheel drive, 4 = 4wd
# cty   city miles per gallon 城市駕駛油耗
# hwy   highway miles per gallon 高速公路駕駛油耗
# fl    汽油: ethanol E85, diesel, regular, premium, CNG
# class 車型
#長條圖geom_bar()
ggplot(data = mpg, aes(x = class, fill= class))+
  geom_bar()+
  labs(x= "車型", y= "數量", title = "mpg長條圖geom_col", subtitle = "洪葦珊")

#長條圖geom_col()
ggplot(data = mpg, aes(x = drv, y=displ, fill= drv))+
  geom_col()+
  labs(x= "drv", y= "排氣量", title = "mpg長條圖geom_col", subtitle = "洪葦珊")

#放射圖coord_polar()
ggplot(data = mpg, aes(x = drv, y=displ, fill= drv))+
  geom_col()+
  coord_polar()+
  labs(x= "drv", y= "排氣量", title = "mpg放射圖geom_col", subtitle = "洪葦珊")

#散佈圖
ggplot(data = mpg, aes(x = cty, y= displ,size=cyl, color= drv))+
  geom_point()+
  labs(x= "城市耗油", y= "高速耗油", title = "iris散佈圖geom_point_size = cyl", subtitle = "洪葦珊")

#盒狀圖
ggplot(data = mpg, aes(x = drv, y= displ, fill= drv))+
  geom_boxplot()+
  labs(x= "drv", y= "排氣量", title = "mpg盒狀圖geom_boxplot", subtitle = "洪葦珊")

#放射圖coord_polar()
ggplot(data = mpg, aes(x = displ, fill= drv))+
  geom_histogram()+
  labs(x= "排氣量",y = "drv", title = "mpg放射圖geom_histogram", subtitle = "洪葦珊")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.