グラフを磨き上げる
以下のコードは、国ごとの幸福度とソーシャル・サポート指数の対話的なプロットを作成し、プロット記号で各国の所得区分を表します。
happy %>%
plot_ly(x = ~social.support, y = ~happiness,
hoverinfo = "text",
text = ~paste("Country: ", country)) %>%
add_markers(symbol = ~income, symbols = c("circle-open", "square-open", "star-open", "x-thin-open"))
あなたのタスクは、読者が情報をより理解しやすくなるように、ホバー情報と軸ラベルを編集することです。
plotly と happy データセットは読み込まれています。
この演習はコースの一部です
R で学ぶ中級インタラクティブ可視化(plotly)
演習の手順
incomeグループ、happinessスコア、social.support指数のホバー情報を追加します。- すべての数値変数をホバー情報内で小数点第2位まで丸めるために、
round(<variable>, 2)を使います。 - x軸ラベルを
"Social support index"、y軸ラベルを"National happiness score"に変更します。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# Complete the following code to polish the plot
happy %>%
plot_ly(x = ~social.support, y = ~happiness,
hoverinfo = "text",
text = ~paste("Country: ", country,
"
Income: ", ___,
"
Happiness: ", ___,
"
Social support: ", ___)) %>%
add_markers(symbol = ~income,
symbols = c("circle-open", "square-open", "star-open", "x-thin-open")) %>%
layout(xaxis = ___,
yaxis = ___)