Exercise 2
In these exercises we look at adjusting the scales and themes of our plots.
Scales
- Using the patient dataset from earlier, generate a scatter plot of BMI versus Weight
library(ggplot2)
patients_clean <- read.delim("patients_clean_ggplot2.txt",sep="\t")
plot <- ggplot(data=patients_clean,
mapping=aes(x=BMI,y=Weight))+geom_point()
plot
- With the plot above, from exercise 1, adjust the BMI axis to show only labels for 20, 30, 40 and the weight axis to show breaks for 60 to 100 in steps of 5 as well as to specify units in y axis label.
- Create a violin plot of BMI by Age where violins are filled using a sequential colour palette.
- Create a scatterplot of BMI versus Weight and add a continuous colour scale for the height. Make the colour scale with a midpoint (set to mean point) colour of gray and extremes of blue (low) and yellow (high).
- Adjust the plot from exercise 4 using scales to remove values greater than 180.
- Adjust the scale legend from plot in exercise 4 to show only 75%, median and min values in scale legend.
- With the plot from exercise 4, create another scatterplot with Count variable mapped to transparency/alpha and size illustrating whether a person is overweight. Is there a better combination of aesthetic mappings?
## Warning: Using size for a discrete variable is not advised.
Statistics
- Recreate the scatterplot of BMI by height. Colour by Age group and add fitted lines (but no SE lines) for each Age group.
Themes
- Remove the legend title from plot in exercise 7, change the background colours of legend panels to white and place legend at bottom of plot.
- Add a title to the plot, remove minor grid lines and save to 7 by 7 inch plot on disk.
- Produce a Height vs Weight scatter plot with point sizes scaled by BMI. Present only the points and title of plot with all other graph features missing.