Polishing axis titles
The axes in a subplot can be renamed using the layout()
command, just like in a single plot; however, there are multiple x-axes to rename. For example, a 2 x 2 grid of plots requires four x-axis labels:
p %>% # subplot
layout(
xaxis = list(title = "title 1"),
xaxis2 = list(title = "title 2"),
xaxis3 = list(title = "title 3"),
xaxis4 = list(title = "title 4")
)
A similar strategy holds for the y-axis labels.
In this example, your task is to polish the axis titles on a subplot. Note that plotly
has already been loaded for you.
This exercise is part of the course
Interactive Data Visualization with plotly in R
Exercise instructions
- For the first plot in
sp2
, use"Global Sales (M units)"
for the y-axis label, and leave the x-axis label blank. - For the second plot in
sp2
, label the x-axis"Year"
and the y-axis"Global Sales (M units)"
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Add x-axis and y-axis labels, and a title to sp2
sp2 %>%
layout(
xaxis = ___(___),
xaxis2 = ___(___),
yaxis = ___(___),
yaxis2 = ___(___)
)