Adding background text
In the previous lesson, you polished your animated bubble chart of housing price index against real GDP. In this exercise, you will continue to polish this graphic by displaying the year in the background of the animation.
This exercise is part of the course
Intermediate Interactive Data Visualization with plotly in R
Exercise instructions
- Add the year as background text. You should center the text at the point (
200000
,450
), set the font color togray80
, and set the font size to150
. - Use
animation_slider()
to hide the slider.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Add the year as background text and remove the slider
us_economy %>%
plot_ly(x = ~gdp, y = ~house_price, hoverinfo = "text", text = ~state) %>%
add_text(x = ___, y = ___, text = ___, frame = ___,
textfont = list(color = ___(___), size = ___)) %>%
add_markers(size = ~population, color = ~region,
frame = ~year, ids = ~state,
marker = list(sizemode = "diameter", sizeref = 3)) %>%
layout(xaxis = list(title = "Real GDP (millions USD)", type = "log"),
yaxis = list(title = "Housing price index")) %>%
___(___ = ___)