Practical session 2: R-tistic Insights- Visualising your data in R

COVID-19 Vaccinations and Death in Malaysia

Task 1: Scatterplots

  1. Call the data in

  2. Create a new variable vaccinated that indicates if an individual is fully vaccinated (dose2) or not. (Tip: use mutate and ifelse)

  3. Plot a scatterplot showing the relationship between age and date. Use the new variable vaccinated variable to color the points using the colour hex #1369FF and #00B556. (Tip: Use the command scale_colour_manual)

  4. Next try using the date_dose3 instead of date. Anything interesting?

Task 2: Line Chart

  1. Create a line chart to represent the cumulative number of vaccinations by dose over time.

  2. Select all the date_doseX, and state

  3. Pivot the data into long form (Tip: use the pivot_long function) and count the number of dose given on each date

  4. Complete the series of dates using complete

  5. Plot the the different doses by date across time and facet by state

  6. Colour date_dose3= #A3D2D5. Maintain the other 2 colours.

  7. Apply a pre-set theme

Task 3: Boxplot

  1. Call data in

  2. Replace all empty cells with NA in column brand2

  3. Group by state and brand2 and summarise the number of groups in each brand, state

  4. Plot a box plot on the distribution of deaths by brand2

  5. Title should be “Number of Deaths by Vaccine Brand and Date” with x-axis labels of “Vaccine Brand” and y-axis labels of “Number of Deaths” (Tip: Use labs)

Task 4: Bar chart

  1. Call in data

  2. Select on state, malaysian, bid

  3. Factorise the variable

  4. Build a grouped bar chart by state and bid status

  5. Facet wrap by malaysian

  6. Title should be “Deaths by State, Brought-in-Dead Status, and Malaysian Status” with x-axis labels of “State” and y-axis labels of “Number of Deaths”. Legend label should be “Brought-in-Dead Status”.

  7. Apply theme_minimal and adjust the x-axis text to be perpendicular (90 degrees) to the axis (Tip: Use theme (axis.text.x=element_text()))

  8. What should you change to transform this into a stacked bar chart?

Task 5: Save plots

  1. Easy peasy lemon squesy- just save all of the above 4 plots. (Tip: use ggsave())

  2. How can we change output format, quality, size