This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| STAT 545A Homework #5 | |
| ======================================================== | |
| Prepared by: Amanda Yuen | |
| Up to this point, we have learned how to generate plots using the lattice package. For homework #5, we will practice generating plots using the ggplot2 package. I'm going to attempt to reproduce some plots from Homework #4 using ggplot2 to compare the results from the lattice and ggplot2 packages. The goal is to make at least two figures, with one being a stripplot-type of figure (one quantitative variable and one categorical variable) and one being a scatterplot (two quantitative variables). | |
| As always, we start by importing the [Gapminder](http://www.stat.ubc.ca/~jenny/notOcto/STAT545A/examples/gapminder/data/gapminderDataFiveYear.txt) data into R and then doing a quick check that the data has been imported properly. | |
| ```{r} | |
| gDat <- read.delim("gapminderDataFiveYear.txt") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| STAT 545A Homework #4 | |
| ======================================================== | |
| Prepared by: Amanda Yuen | |
| For homework #4, we will evaluate code prepared by someone else for last week's data aggregation tasks and produce graphics to accompany these tasks. | |
| As always, we begin by importing the [Gapminder](http://www.stat.ubc.ca/~jenny/notOcto/STAT545A/examples/gapminder/data/gapminderDataFiveYear.txt) data into R and do a quick check that the data has been imported properly. | |
| ```{r} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| STAT 545A Homework #3 | |
| ======================================================== | |
| Prepared by: Amanda Yuen | |
| This is an R Markdown document. For homework #3, we will perform some data aggregation tasks on the [Gapminder](http://www.stat.ubc.ca/~jenny/notOcto/STAT545A/examples/gapminder/data/gapminderDataFiveYear.txt) data. | |
| First, let's import the data into R. | |
| ```{r} | |
| gDat <- read.delim("gapminderDataFiveYear.txt") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| STAT 545A Homework #2 | |
| ======================================================== | |
| Prepared by: Amanda Yuen | |
| This is an R Markdown document. For homework #2, we will carry out a brief analysis of the Gapminder data located [here](http://www.stat.ubc.ca/~jenny/notOcto/STAT545A/examples/gapminder/data/gapminderDataFiveYear.txt). | |
| Let's import the data into R: | |
| ```{r} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| a <- 2 | |
| b <- -3 | |
| n <- 40 | |
| sigSq <- 0.5 | |
| x <- runif(n) | |
| y <- a + b * x + rnorm(n, sd = sqrt(sigSq)) | |
| (avgX <- mean(x)) | |
| write(avgX, "avgX.txt") | |
| plot(x,y) | |
| abline(a, b, col = "purple") |