Plotly Graph

data(wrld_simpl)

slave_trade$isocode[slave_trade$isocode == 'ZAR'] <- 'COD'
isocodes <- slave_trade$isocode

afr <- wrld_simpl[wrld_simpl$REGION == 2, ]

afr_proj <- afr %>%
  st_as_sf %>%
  st_transform(3857)

geo_and_slave <- merge(x = afr_proj, 
      y = slave_trade, 
      by.x = 'ISO3',
      by.y = 'isocode',
      all = TRUE)
p1 <- ggplot(data = slave_trade,
       mapping = aes(x = ln_export_area,
                 y = ln_maddison_pcgdp2000)) +
  geom_point(mapping = aes(size = land_area,
                          text = country,
                          color = ethnic_fractionalization),
             alpha = 0.7) +
  geom_smooth(method = 'lm',
              formula = y ~ x,
              se = FALSE,
              color = 'black') +
  labs(title = 'Higher slave exports are associated with present-day poverty',
       subtitle = 'Points scaled by area of country',
       caption = 'Source: Nathan Nunn',
       y = 'Log real per capita GDP in 2000',
       x = 'Log slave exports normalized by land area') +
  guides(size = 'none') + 
  scale_color_distiller(palette = 'YlOrRd',
                     direction = 0,
                     name = 'Ethnic\nFractionalization') + 
  theme_bw() +
  theme(panel.grid.major = element_blank(),
                 panel.grid.minor = element_blank(),text = element_text(family = 'serif', size = 12))

ggplotly(p1, tooltip = 'text') %>%
  layout(title = list(text = paste0('Higher slave exports are associated with present-day poverty',
                                    '<br>',
                                    '<sup>',
                                    'Points scaled by area of country',
                                    '</sup>')))