添加背景文本
在上一课中,您已对房价指数与实际 GDP 的气泡动画图进行了润色。本练习中,您将继续完善该图,通过在动画背景中显示年份来增强表达力。
本练习是课程的一部分
R 中级交互式数据可视化(plotly)
练习说明
- 将年份添加为背景文本。请将文本居中放在点 (
200000,450) 处,字体颜色设为gray80,字体大小设为150。 - 使用
animation_slider()隐藏滑块。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# 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")) %>%
___(___ = ___)