These exercises cover the sections of Plotting in R PlottingInR.

Quesions 2

Please load the dateset subset_GoT from "Got_dataset/subset_GoT.csv" and use ggplot2 to

  1. create a bar plot using subset_GoT$social_status and see the number of characters that are Highborn or Lowborn. We will plot this data for the rest of the questions in this section.

    1. assign colours according to whether the characters switched their allegiance (subset_GoT$allegiance_switched)

    2. add argument position=position_dodge() in the geom_bar() function and see what effect this has

  2. use the facet_wrap() function to separate the figure according to the character’s sex

  3. use the facet_grid() function to separate the figure according to the character’s sex and occupation

  4. use the facet_wrap() function to separate the figure according to the character’s sex and occupation, and compare the difference from your answer to (4)

  5. save the final figure as “pdf” file

[hint: use read.csv() function to load Got_dataset/subset_GoT.csv]

subset_GoT<-read.csv(file="Got_dataset/subset_GoT.csv")

head(subset_GoT)