plot_ly(
data = gapminder %>% filter(year == 2007),
x = ~gdpPercap,
y = ~lifeExp,
type = 'scatter',
mode = 'markers',
size = ~pop,
color = ~continent,
colors = viridis::plasma(n = 5, end = .93),
text = ~paste(
'Country: ', country,
'<br>GDP per capita:', scales::dollar(gdpPercap, 1),
'<br>Life Expectancy:', scales::comma(lifeExp, 1),
'<br>Population:', scales::comma(pop)
),
hoverinfo = 'text',
sizes = c(5, 100)
) |>
layout(
title = 'Gapminder data in 2007',
xaxis = list(title = 'GDP per capita (log scale)', type = 'log'),
yaxis = list(title = 'Life Expectancy')
)