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
vaccinated
that indicates if an individual is fully vaccinated (dose2) or not. (Tip: usemutate
andifelse
)Plot a scatterplot showing the relationship between
age
anddate
. Use the new variablevaccinated
variable to color the points using the colour hex#1369FF
and#00B556
. (Tip: Use the commandscale_colour_manual
)Next try using the
date_dose3
instead 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
, andstate
Pivot the data into long form (Tip: use the
pivot_long
function) and count the number of dose given on each dateComplete the series of dates using
complete
Plot the the different doses by date across time and facet by
state
Colour
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
brand2
Group by
state
andbrand2
and summarise the number of groups in eachbrand
,state
Plot 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
,bid
Factorise the variable
Build a grouped bar chart by
state
andbid
statusFacet wrap by
malaysian
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”.
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