5. [10 marks]
This question relates to the following code, which produces an interactive scatterplot that looks similar to the image below (except that it is interactive).
library(ggplot2)
library(plotly)
sharedf <- highlight_key(singapore, ~ gender)
gg <- ggplot(sharedf) +
geom_point(aes(x=1:30, y=age, text=gender),
color=c(3, 4, rep(1, 28)), size=3)
pg <- ggplotly(gg)
highlight(pg, on = "plotly_selected", color = "red")
(a) [7 marks]
Explain in detail the purpose of every line of the code above, including the meaning of all functions and arguments.
(b) [3 marks]
Describe what would happen in the interactive scatterplot for each of the following interactions (if we perform these interactions one after the other, in
the order below):
• We hover the mouse cursor over the green data symbol in the scatterplot.
• We select the green data symbol in the scatterplot (by clicking and dragging a rectangular selection around just that data symbol).
• We select the blue data symbol (by clicking and dragging a rectangular selection around just that data symbol).