Instruction

  1. Create your own new R markdown file in your RStudio (and remove unnecessary parts if needed)
  2. Create a code chunk and Write your own code to replicate the plot in each problem
  3. Knit your R markdown to Microsoft Word
  4. Submit the word file to 턴잇인(Turnitin) in Week6 section.
  5. (Optional) You can Knit to your R markdown to HTML, and then publish your R markdown to http://rpubs.com/ (see lecture video on “R markdown” for more details how to publish your R markdown to rpubs.com or visit https://rpubs.com/about/getting-started). Once you publish your R markdown for your HW to rpubs.com, then add your link (e.g., https://rpubs.com/sblee/hw1) at the TOP of your submitted word file and indicate you did extra job for web publish (e.g., “I publish my HW on the rpubs”). If do this, you can get 10% of bonous points.

Problem 1

Using the mpg dataset in the ggplot2 package, replicate the plot below using the following settings:

# you need `ggplot2` package to use `mpg` dataset
library(ggplot2)

Problem 2

Using the mpg dataset in the ggplot2 package, replicate the plot below using the following settings:

# you need `ggplot2` package to use `mpg` dataset
library(ggplot2)

Problem 3

Using the midwest dataset in the ggplot2 package, replicate the plot below using the following settings:

library(ggplot2) # you need `ggplot2` to use `midwest` data
options(scipen=999)  # turn-off scientific notation like 1e+48

ggplot(data = mpg, mapping = aes(x = displ, y = hwy)) +

geom_point(aes(color=drv)) + geom_smooth(method="lm") +

labs(title ="MPG vs Engine size", x = "Engine size", y = "MPG")
## `geom_smooth()` using formula 'y ~ x'

Problem 4

Using the iris dataset in the datasets package (dataset package belongs to Base R and so you don’t need to download the package), replicate the plot below using the following settings:

(iris is another famous dataset in R. You may google or check the this link to learn more about the dataset)

Problem 5

Using the heightweight dataset in the gcookbook package, replicate the plot below using the following settings:

library(gcookbook)

Problem 6

Using the mpg dataset in the ggplot2 package, replicate the plot below using the following settings:

library(ggplot2)