12 Practical Day Five
Excellent practice is all of the questions in the R4DS Data Visualisation introduction, so I suggest you do them (probably skipping the non-coding questions, so as to get through the content faster).
In addition, most (if not all) of Birgit’s uploaded questions involve plots, so you can use those as practice too. They also have the advantage that they will involve learning relevant statistical and mathematical functions.
However, for this practical, here are the questions you will need to answer:
12.1 Question One
- Simulate 100 random numbers from a normal distribution with mean 3 and standard deviation 1. Use
ggplot2to plot the empirical density of these, and format the plot according to best practice (e.g. with axis titles, caption, etc.). - Make a reference to the plot in the text (e.g. using
@fig-dens-plot). - Overlay the true density of the normal distribution on the plot (hint: use
geom_line).
12.2 Question Two
Calculate a two-way frequency table of species of penguins and island location (from the palmerpenguins package’s dataset), and display it according to best practices (e.g. table caption, appropriate lines, etc.).
12.3 Question Three
Plot the distribution of the flipper length of penguins, separated by species. Create three plots:
- All species in the same plot, using the
geom_boxplotfunction. - All species in the same plot, and use the
geom_densityfunction (hint: use thealphaparameter to make overlapping densities more visible). - Each species in a separate facet.
These plots need not include captions or be referenced in the text, but should follow other best practices.