I am trying to keep a legend which is generated when I use ggplot, but upon applying plotly the legend disappears. Here is my code:
ggplotchange <- ggplot(data = map.world1, aes(x = long, y = lat, group = group, fill = happiness, text = paste("Country:", region, "<br>", "Happiness:", -happiness, "<br>", "Economy:", economy, "<br>", "Family:", family, "<br>", "Health:", -health, "<br>", "Freedom:", -freedom, "<br>", "Trust:", trust, "<br>", "Generosity:", generosity))) +
geom_polygon() +
scale_fill_gradientn(colors = ocean.curl(150)) +
theme(
panel.grid = element_blank(),
axis.text = element_blank(),
axis.title = element_blank(),
axis.ticks = element_blank(),
legend.title = element_blank(),
plot.title = element_text(hjust = 0.5)) +
labs(title = "Change from 2015 to 2022") +
guides(fill = guide_legend(title=""))
ggplotly(ggplotchange, tooltip = c("text"))
The dput of the map.world1 data is this:
structure(list(long = c(-69.8991241455078, -69.8957061767578,
-69.9421920776367, -70.004150390625, -70.0661163330078, -70.0508804321289
), lat = c(12.4520015716553, 12.4229984283447, 12.4385251998901,
12.50048828125, 12.5469722747803, 12.5970697402954), group = c(1,
1, 1, 1, 1, 1), order = 1:6, region = c("Aruba", "Aruba", "Aruba",
"Aruba", "Aruba", "Aruba"), subregion = c(NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_),
region.y = c(NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_), happiness = c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), economy = c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), family = c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), health = c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), freedom = c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), trust = c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), generosity = c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_)), row.names = c(NA,
6L), class = "data.frame")