Practical session 2: R-tistic Insights- Visualising your data in R
COVID-19 Vaccinations and Death in Malaysia
Task 1: Scatterplots
Call the data in
Create a new variable
vaccinatedthat indicates if an individual is fully vaccinated (dose2) or not. (Tip: usemutateandifelse)Plot a scatterplot showing the relationship between
ageanddate. Use the new variablevaccinatedvariable to color the points using the colour hex#1369FFand#00B556. (Tip: Use the commandscale_colour_manual)Next try using the
date_dose3instead of date. Anything interesting?
Task 2: Line Chart
Create a line chart to represent the cumulative number of vaccinations by dose over time.
Select all the
date_doseX, andstatePivot the data into long form (Tip: use the
pivot_longfunction) and count the number of dose given on each dateComplete the series of dates using
completePlot the the different doses by date across time and facet by
stateColour
date_dose3=#A3D2D5. Maintain the other 2 colours.Apply a pre-set theme
Task 3: Boxplot
Call data in
Replace all empty cells with NA in column
brand2Group by
stateandbrand2and summarise the number of groups in eachbrand,statePlot a box plot on the distribution of deaths by brand2
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
Call in data
Select on
state,malaysian,bidFactorise the variable
Build a grouped bar chart by
stateandbidstatusFacet wrap by
malaysianTitle 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”.
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()))What should you change to transform this into a stacked bar chart?
Task 5: Save plots
Easy peasy lemon squesy- just save all of the above 4 plots. (Tip: use
ggsave())How can we change output format, quality, size