Homework 1
data(mtcars)
View(mtcars)
names(mtcars)
## [1] "mpg" "cyl" "disp" "hp" "drat" "wt" "qsec" "vs" "am" "gear"
## [11] "carb"
install.packages('ggplot2')
## Installing package into 'C:/Users/txizi/Documents/R/win-library/3.4'
## (as 'lib' is unspecified)
## package 'ggplot2' successfully unpacked and MD5 sums checked
##
## The downloaded binary packages are in
## C:\Users\txizi\AppData\Local\Temp\RtmpKAIBBw\downloaded_packages
library(ggplot2)
Most of the cars are 4-carb and 2-carb;Very few are 6-carb and 8-carb; Most cars are under 4 carbs
pie <- ggplot(mtcars, aes(x = factor(1), fill = factor(carb))) +
geom_bar(width = 1)
pie + coord_polar(theta = "y")+labs(x='Pie chart of Carb')

Most of the cars surveyed in the database have 3-gears, followed by 4-gears and the last one is 5-gears;5-gears’s number is around 1/3 of 3-gear’ and less then 1/2 of 4-gears’.
pl2=ggplot(mtcars,aes(factor(gear)))+geom_histogram(stat="count")
## Warning: Ignoring unknown parameters: binwidth, bins, pad
pl2

Among the 3 gears, most cars have 8 cylingder, 4 cylinders cars are very little; 4-gear cars are completely different. Most cars are 4 cyclinder, the rest are 6 cylinders; For 5-gear cares, about 2 cars are 8 cylinders and 4 cylinders, only one car is 6 cylinder.
pl3=ggplot(mtcars,aes(x=factor(gear),fill=factor(cyl)))+geom_bar()
pl3+ggtitle('stacked-bar')

There seems to be a linear relationship between mpg and weight; the more the weight is, the less the mpg.
pl4=ggplot(mtcars,aes(x=wt,y=mpg))+geom_point(color='blue')
pl4

Looks like the more carbs a car has, the more horspower it has; car with 4 and more carbs clearly has more hp than 1 carb cars.
pl5=ggplot(mtcars,aes(x=factor(carb),y=hp))+geom_boxplot()
pl5
