15 Plots exercises
These exercises will primarily use the “penguin_df” from the theory and practice session.
Please use your “Exercises.R” script for this exercise and the main workshop directory as the working directory. Ensure you are using annotations and code sections to keep the contents clear and separated.
For convenience the code to load the Penguin data frame directory will be:
<- read.csv("Chapter_13-16/penguin.tsv",
penguin_df check.names = FALSE,
stringsAsFactors = TRUE,
sep = "\t"
)
Your plots might not look exactly the same. As long as your plot contains the same data it is good. If you are not sure if your plot is correct, feel free to look at the solutions to look at my code.
15.1 Line graph
First we will ignore “penguin_df”.
Create the below plot. You will need to create the vectors yourself.
Tip: The x and y labels may help you figure out the commands to create the vectors.
15.2 Histogram
From the “penguin_df” create the below plot:
Note: The colour of the bars are “blue”.
15.3 Scatterplot
From the “penguin_df” create the below plot:
Note: You can check what numbers refer to what shape for pch =
at: http://www.sthda.com/english/wiki/r-plot-pch-symbols-the-different-point-shapes-available-in-r
Before you continue save this plot. Details below:
- Save the file as a png called “Penguins_2009_bill_depth_vs_length_scatterplot.png”
- Save the plot with a width and height of 250 and resolution of 150
15.4 Boxplot
From the “penguin_df” create the below plot:
Note: Make sure the x axis is in the same order as below.
For the last task, save this plot. Details below:
- Save the file as a jpg called “Penguins_species_and_flipper_length_boxplot.jpg” in “Chapter_13-16”.
- Save the plot with a width of 300, height of 250, and resolution of 150