CommencezCommencez gratuitement

Ajouter du texte en arrière-plan

Dans la leçon précédente, vous avez peaufiné votre nuage de points animé comparant l'indice des prix des logements au PIB réel. Dans cet exercice, vous allez continuer à améliorer ce graphique en affichant l'année en arrière-plan de l'animation.

Cette activité fait partie du cours

Visualisation de données interactive intermédiaire avec plotly en R

Voir le cours

Instructions de l’exercice

  • Ajoutez l'année comme texte d'arrière-plan. Centrez le texte au point (200000, 450), définissez la couleur de la police à gray80 et la taille de la police à 150.
  • Utilisez animation_slider() pour masquer le curseur.

Exercice interactif pratique

Essayez cet exercice en complétant ce code d’exemple.

# 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")) %>%
  ___(___ = ___)
Modifier et exécuter le code