R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00

Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.

1. Create a pie chart showing the proportion of cars from the mtcars data set that have different carb values

data(“mtcars”) summary(mtcars)

Install ggplot2 package

install.packages(“ggplot2”) library(ggplot2)

Through the pie chart, we can see that carb 2 and 4 are 31.25% each, and carb 1 is 21.875%. There is 0% in carb1. The rests have smaller proportions.

2. Create a bar graph, that shows the number of each gear type in mtcars.

Based on the bar graph, No.3 Gear has the most Car distribution, No.4 and No.5 ranked second and third in car distribution.

3. Next show a stacked bar graph of the number of each gear type and how they are further divided out by cyl.

By looking at the stacked bar graph of the number of each gear type, Factor 4 gears are mainly used in 4 & 6 cylinder cars, whereas Factor 3 gears are mainly used in 8-cylinder cars and have the most cars. Factor 5 has the leaset cars in all Cylinder types.

4. Draw a scatter plot showing the relationship between wt and mpg.

##From the above graph, we can see that Weight and Miles per gallon are inversely correlated to each other, which means that as the heavy weight cars tend to have more mileages.

5. Design a visualization of your choice using the data and write a brief summary about why you chose that visualization.

##This is the distribution that was chosen to analyze the distribution of car mileage within the dataset. we can tell that there is a peak point at around 17-18 Miles Per Gallon. It seems like a distribution skewed to right.

install.packages(“knitr”) library(knitr) install.packages(“rmarkdown”) library(rmarkdown)