For this exam, you need package ‘ggplot2’: install.packages(“ggplot2”). Two datasets that are shipped with the ggplot2 package: diamonds: describing the prices of more than 50,000 cut diamonds and msleep describing the sleep times of 83 mammals. Then,
- Create a scatterplot with carat along the x-axis and price along the y-axis. Change the x-axis label to read “Weight of the diamond (carat)” and the y-axis label to “Price (USD).” Use cut to set the color of the points.
- Try adding the argument alpha = 1 to geom_point, i.e. geom_point(alpha = 1). Does anything happen? Try changing the 1 to 0.5 and 0.25 and see how that affects the plot.
- Change the scatterplot from above, so that diamonds with different cut qualities are represented by different shapes.
Change the scatterplot from above, so that the size of each point is determined by the diamond’s length, i.e. the variable x.