Reputation: 33
I want to color the areas of Germany in a map using plotly without lines for the borders. In my example the shape of the areas change (some triangles are added) when specifying mode="none" and I don't understand why. I want to use plotly and not plot for plotting the map because I want to create an interactive map. It would be great if someone could help me!
install.packages("rgeos")
install.packages("raster")
install.packages("sf")
install.packages("plotly")
install.packages("shiny")
library(rgeos)
library(raster)
library(sf) #converting map in a format for plotly
library(plotly)
library(shiny)
Germany <- getData('GADM', country='DE', level=1)
germany_sf<- st_as_sf(Germany)
germany_sf$fill <- c(rep(c("blue", "green", "purple", "orange"),4))
plot_ly(germany_sf, type="scatter", mode="none", split= ~ VARNAME_1, fillcolor= ~fill, opacity= 0.4, showlegend=FALSE)
plot_ly(germany_sf) #correct shape but with lines for borders and not specific fillcolors.
```
Upvotes: 2
Views: 368
Reputation: 24262
To avoid colored borders, you can use the following solution:
plot_ly(germany_sf, type="scatter", split= ~VARNAME_1,
fillcolor= ~fill, color=NA, opacity=0.4, showlegend=FALSE)
Upvotes: 2