Skip to content

Instantly share code, notes, and snippets.

@geoffwoollard
Last active December 22, 2015 23:19
Show Gist options
  • Save geoffwoollard/6545701 to your computer and use it in GitHub Desktop.
Save geoffwoollard/6545701 to your computer and use it in GitHub Desktop.
stat545a-2013-hw02_woollard-geo
========================================================
Let's explore the gap minder data. You can find it [here](http://www.stat.ubc.ca/~jenny/notOcto/STAT545A/examples/gapminder/data/gapminderDataFiveYear.txt)
```{r}
library(lattice)
gdURL <- "http://www.stat.ubc.ca/~jenny/notOcto/STAT545A/examples/gapminder/data/gapminderDataFiveYear.txt"
gDat <- read.table(gdURL, header = TRUE, sep = '\t', quote = "\"")
```
What is in gDat?
```{r}
str(gDat)
```
Some elementary statistics
```{r}
summary(gDat)
```
The year range
```{r}
min(gDat$year)
max(gDat$year)
```
Does the data seem reasonable?
* China is Big
* Japan is Healthy
```{r}
gDat[which(gDat$pop == max(gDat$pop)),]
gDat[which(gDat$pop == max(gDat$pop)),]$pop
gDat[which(gDat$lifeExp == max(gDat$lifeExp)),]
gDat[which(gDat$lifeExp == max(gDat$lifeExp)),]$lifeExp
```
Let's make some **pictures**.
* How has life changed since the post WW2 era?
```{r fig.width=7, fig.height=6}
xyplot(pop ~ year | continent, gDat)
```
Very interesting! Where are all those lovely asians coming from?
```{r fig.width=7, fig.height=6}
xyplot(pop ~ year | country, subset(within.data.frame(gDat, country <- strtrim(gDat$country,8) ), continent == "Asia"))
```
@songcai
Copy link

songcai commented Sep 19, 2013

When you see something 'very interesting', why not go a little further to explain what/why is so interesting?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment