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.
Diese Übung ist Teil des Kurses
Intermediate Interactive Data Visualization with plotly in R
Anleitung zur Übung
- 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.
Interaktive Übung
Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.
# 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")) %>%
___(___ = ___)