Find us on GitHub

Week 7: moRe

For this weeks Challenges I want something a little different. By all means do the challenges in the readings; the answers are all at the bottom of each page. So, they are not the best option for assessment! See the heading "Assignment" below for what I want you to turn in this week.

Subsetting Data Structures

Data Frames

Creating publication quality graphics

ggplot(gapminder,
       aes(x = year, y = lifeExp)) + 
  geom_line(aes(color = continent)) + 
  facet_wrap(~country) + 
  xlab("Year") + 
  ylab("Life Expectancy") + 
  scale_colour_discrete(name="Continent") +
  theme(axis.text.x = element_blank(), 
        axis.ticks.x = element_blank())
ggsave("graphs/lifebyyearbycountry.png")

Vectorization

Assignment

The file for this weeks assignment will be a commented R script. The file should be saved with a name like yourlastname_week7.R, and uploaded as an attachment. At the top of the file write a comment (start the line with #) with the week number and your name on one line. If none of that makes sense, go watch the start of the video for subsetting vectors.

Write the code to do the following:

  1. Read in the gapminder dataset.
  2. Make a line plot of per capita GDP by year for each country in Asia. There should be a line for each country in Asia. There should not be any other continents in the plot.
  3. Save the plot to a png file in the graphs subdirectory of your project.

I should be able to run your script from the main directory of the project created in week 6 using source("code/yourlastname_week7.R") from a clean start of R. To test your code to make sure it works without errors, first click on the Session menu, and choose Restart R. Then open your file and click the source button in the top right corner. This will load your file and run it; any output to the console is suppressed. Check the date and time of the saved image file to make sure the script ran correctly.

This challenge is due on Friday of Week 7 (Feb 26) at 5 pm. Late assignments will receive a score of zero unless prior approval is granted.