I am trying to make some interactive maps of the United States with basic tooltips using plotly. However, whenever I render the map the aspect ratio of the plot is 'off', the map looks like it has been stretched and it just looks odd.
library(readxl)
library(dplyr)
library(tidyr)
library(urbnmapr)
library(plotly)
library(ggplot2)
states_territory <- urbnmapr::get_urbn_map(map = "territories_states",
sf = FALSE)
states_territory <- data.frame(states_territory)
states_territory %>%
ggplot(aes_string(x = 'long',
y = 'lat',
group = 'group',
text = 'state_name')) +
geom_polygon(color = "#ffffff", size = 0.25) +
coord_map(projection = "albers", lat0 = 39, lat1 = 45) -> test_plot
plotly_plot <- ggplotly(test_plot,
tooltip = 'text')
plotly_plot
Rendering the code above should contain everything for a REPEX but please let me know if theres something I need to add.
This is a plot that will be inserted into a Shiny app, I have the app working but I am unable to get the plot to have the clean look Im hoping for.
If anyone has any suggestions to remedy this or any other interactive plotting methods, it would be much appreciated. I have already tried ggiraph, and while the plot looks nice, ggiraph does not autoscale in an R shiny context.
Thanks a bunch
