背景テキストの追加
前のレッスンでは、住宅価格指数と実質 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")) %>%
___(___ = ___)