Chapter 11 The subtle art of cannibalisation - Week 12 - Workshop 3
In this Week 12 workshop we will be applying the rules of aesthetics that we learned in the last two chapters to the rest of our plots. You may use functions and arguments from your ggplot_fundamentals.r
script to modify the plots you made in previous weeks. This is a very common practice, especially while learning a new programming language, you get a script or chunk of code right once and then canibalise parts of it for other uses, modifying it as needed to fit its new purpose.
11.1 Starting on the right footing
In the last few chapters, and over the last few weeks you have been asked to modify quite a few chunks of script. If anything hasn’t made sense or you haven’t managed to get some chunks or functions working please do let either myself or a demonstrator know before you start the workshop activity. We are here to help!
11.2 Beautifying your box plots
In Chapters 9 and 10 we specifically worked on making changes to our box plots that would make them clean, clear and visually pleasing. You have all the code already made for your box plots, it just needs tailoring a little. You should have three boxplots saved in your figures
folder (made in Chapter 8.1);
- size_differences_by_sex_boxplot.pdf
- size_differences_by_treatment_boxplot.pdf
- size_differences_boxplot.pdf - remember this is filled by
sex
nottreatment
so will be subtly different to the figure made in theggplot_fundamentals.R
.
Using the script from ggplot_fundamentals.R
make the necessary modifications to each of these three figures so that they are clean, clear and visually pleasing. Make sure you save each one to your figures
folder using ggsave
.
11.3 Beautifying your histograms
You hopefully also have two histograms saved in your figures
folder (made in Chapter 7);
- size_histogram.pdf
- parasite_histogram.pdf
Use you previous chunks of scripts and knowledge of R to edit the labels and themes of this plot. Print it again and take a look. When you’re happy save your updated figures to the figures
folder using ggsave
.
11.4 Beautifying your scatter plot
You hopefully also have a scatter plot saved in your figures
folder (made in Chapter 8.2);
- size_vs_parasites_point.pdf
Use you previous chunks of scripts and knowledge of R to edit the labels and themes of this plot. Print it again and take a look.
Now there are some additional elements in this plot that could be adjusted. These include;
- Point shape - The shape of the individual points on the plot, as with colours there are lots of options numbered 0 - 25, descriptions of each one are listed here
- Point size - The size of each point
- Point colour - The colour of your points
- Line type (solid, dashed, etc) - Again thre are several options here, the notation and descriptions of which can be found here
- Line colour
- Line size - the weight of the line
- Line fill - Note that here this refers to the colour of the shaded area marking the standard error
So lets play with some of these. Try adding and adjusting the following arguments within geom_point()
shape = 1
- have a look at other point shapes you could use and play with this settingsize = 2
- again try playing with some point sizescolour = "blue"
- or any other colour you fancy trying.
Once you are happy with your points we can take a look at your regression line. Try adding and adjusting the following arguments within geom_smooth()
colour = "cornflowerblue"
fill = "lightblue"
size = 1
linetype = "dashed"
As before please do experiment and play with the settings described by each of these arguments.
Once you are happy with your new and beautiful scatter plot make sure you save it to to the figures
folder using ggsave
.
11.5 A Challenge!
Try to adjust the chunk for your size vs parasites scatter plot so that the points are coloured by sex
and shaped by treatment
. Colour female points "deepskyblue3"
and male points "coral"
and use solid squares for the 30°C treatment and solid circles for the 35°C treatment. Make sure the text and titles for your legends are correct and well presented.
Hint - to do this you will need to correctly use and populate the aes()
function in geom_point()
and then to adjust colours, shapes and associated text you will need to pipe +
to the scale_color_manual()
and the scale_shape_manual()
functions. You will also need to adjust the settings in the labs()
function to change the legend titles.
11.6 Formative Assignment
This is the last of the taught content for the Introduction to Data Science sub module. You should all be very proud of yourselves for completing the first half of this workbook! You now have the opportunity to submit a formative assignment, this is hosted in PebblePad and can be accessed through the BIO-4008Y page on blackboard in the Data Science Learning Module. Details of the task can be found in Chapter 12.
See you all in the new year :)
11.8 References
Wickham, Hadley, Mara Averick, Jennifer Bryan, Winston Chang, Lucy D’Agostino McGowan, Romain François, Garrett Grolemund, et al. 2019. “Welcome to the tidyverse.” Journal of Open Source Software 4 (43): 1686. https://doi.org/10.21105/joss.01686.
Wickham, Hadley, Winston Chang, Lionel Henry, Thomas Lin Pedersen, Kohske Takahashi, Claus Wilke, Kara Woo, Hiroaki Yutani, and Dewey Dunnington. 2021. Ggplot2: Create Elegant Data Visualisations Using the Grammar of Graphics. https://CRAN.R-project.org/package=ggplot2.