Open SebastianKrog opened 4 years ago
I am also having this issue.
@PhazeDK , I found a simple solution (using sf::st_cast(..., "MULTIPOLYGON")
) that worked for me, try this:
library(ggplot2)
library(geojsonsf)
library(plotly)
library(sf)
dk_map <- geojson_sf("https://raw.githubusercontent.com/moestrup/covid19/master/test.json")
dk_map <- sf::st_cast(dk_map, "MULTIPOLYGON")
mainland <- ggplot(data=dk_map) + geom_sf()
mainland
ggplotly(mainland)
I'm having the same issue when following the tutorial in the book for catograms: (https://plotly-r.com/maps.html#cartograms)
library(cartogram)
library(albersusa)
us_cont <- cartogram_cont(usa_sf("laea"), "pop_2014")
plot_ly(us_cont) %>%
add_sf(
color = ~pop_2014,
split = ~name,
span = I(1),
text = ~paste(name, scales::number_si(pop_2014)),
hoverinfo = "text",
hoveron = "fills"
) %>%
layout(showlegend = FALSE) %>%
colorbar(title = "Population \n 2014")
also gives the error you specified.
So this is probably something that was introduced in a recent commit, otherwise it wouldn't be in the book I guess.
The workaround above works, but is obviously not the desired solution.
Just bumping this a bit:
I work around the inability to handle GEOMETRY sf's by splitting my sf tables into (MULTI)LINESTRING, (MULTI)POINT and (MULTI)POLYGON tables and adding each as a new trace. This avoids the "cannot handle GEOMETRY" problem, however it does mean that I have 3 legend entries, (one line-style, one point-style, one filled line-style respectively). This means its a pain for users to toggle an entry on or off, they have to do all 3. Yes, I could use legendgroups, but that only works if I haven't already got a legendgroup.
I understand why it can't handle GEOMETRY well (let's be honest, the handling of polygons is a bit of a hack as it is), as it requires a different processing stream/plot type for each geometry type, but it would be very much of use to have it done internally. Whether this means that a sub-legendgroup needs inventing or a logical grouping of traces other than via a legend group which all behave off the same event, I have no answer.
Hi,
I am trying to convert this geom_sf plot to plotly, but I keep receiving an error:
Gives the following output:
I thought this was related to issue #1659, and tried installing the newest version of plotly from github (4.9.2.9000) but am still seeing the error above.