Plotting and data visualization in base R Answer Key

Author

Will Gammerdinger

Published

December 5, 2025

Exercise 1

  1. Change the color scheme in the scatterplot, such that it reflects the genotype of samples rather than celltype.
# Create factor of genotype
new_metadata$genotype <- factor(new_metadata$genotype)

# Create plot
plot(samplemeans ~ age_in_days, data=new_metadata,
     main="Expression changes with age",
     xlab="Age (days)",
     ylab="Mean expression",
     pch="*",
     cex=2.0,
     col=c("blue", "green")[genotype])

# Add legend
legend("topleft",
       pch="*",
       col=c("blue", "green"),
       c("A", "B"),
       cex=0.8,
       title="Genotype")

  1. Use R help to find out how to increase the size of the text on the axis labels.
# Open graphical parameters help page
?par