library(gapminder)
data(gapminder)
Using the gapminder data, make a line plot showing the population of Afghanistan over time. Hint: for base R, look at the help for plot.default and the type parameter.
Make sure to clean up the x and y labels, and give your plot a title.
plot(x=gapminder$year[gapminder$country=="Afghanistan"],
y=gapminder$pop[gapminder$country=="Afghanistan"],
type="l",
xlab="Year",
ylab="Population",
main="Afghanistan Population")
Make a histogram of life expectancies in 2007. Make the historgram with each of 5, 10, 20, and 40 bins. Does the number of bins change your interpretation of the data at all? Do you see different trends?
## repeat, changing the number of breaks
hist(gapminder$lifeExp[gapminder$year==2007], breaks=5)
With more bins, ie becomes more obvious that there are at least two sets of countries in the data. There’s a cluster of high life expectancy, then a large spread of countries with lower life expectancy.
Using the gapminder data, create a scatter plot of gdpPercap vs. population for year 1982. Log the x axis (hint: argument log="x"). Change the plot marker to a solid circle, color red, with a alpha value of .3.
## repeat, changing the number of breaks
plot(x=gapminder$pop[gapminder$year==1982],
y=gapminder$gdpPercap[gapminder$year==1982],
log="x",
pch=16,
col=rgb(1,0,0, alpha=.3))