Plot: GDP vs Life Expectancy

GDP per capita versus life expectancy, colored by continent.

library(plotly)
## Warning: package 'plotly' was built under R version 4.4.3
## Warning: package 'ggplot2' was built under R version 4.4.3
library(gapminder)
## Warning: package 'gapminder' was built under R version 4.4.3
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.4.3
# Prepare data
data_2007 <- gapminder %>% filter(year == 2007)

# Create interactive plot
plot_ly(data_2007,
        x = ~gdpPercap,
        y = ~lifeExp,
        type = 'scatter',
        mode = 'markers',
        color = ~continent,
        size = ~pop,
        text = ~country,
        marker = list(opacity = 0.7, sizemode = 'diameter')) %>%
  layout(title = "GDP per Capita vs Life Expectancy (2007)",
         xaxis = list(title = "GDP per Capita", type = "log"),
         yaxis = list(title = "Life Expectancy"))
## Warning: `line.width` does not currently support multiple values.
## Warning: `line.width` does not currently support multiple values.
## Warning: `line.width` does not currently support multiple values.
## Warning: `line.width` does not currently support multiple values.
## Warning: `line.width` does not currently support multiple values.