Hover text inside of multipolygon, not just on borders

Dear reader,

I am making (interactive) maps in R using multipolygons. When I hover over the map, the text only shows up when hovering over the borders of the multipolygons. However, I want the text to also show up when having my mouse on the inside of the multipolygon. I have tried multiple different ways to try and fix this, but I can't seem to find the solution. Any help is welcome! Thank you in advance.

Information:

The values under the multipolygon variable look as follows:

"geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ 259217.534800000488758, 557608.082100000232458 ], [ 259293.996899999678135, 557658.11710000038147 ], [ 259653.594900000840425, 557460.405099999159575 ], [ 259872.941100001335144, 557238.791000001132488 ], [ 260114.452899999917, 557391.728100001811981 ], [ 260356.136900000274181, 556999.171100001782179 ], [ 260397.0760000012815, 557023.397999998182058 ], [ 260693.195900000631809, 556525.810100000351667 ], [ 260631.541900001466274, 556471.067099999636412 ], [ 261083.656899999827147, 556007.221099998801947 ], [ 260914.541900001466274, 555883.878100000321865 ], [ 260901.922899998724461, 555896.799100000411272 ], [ 259217.534800000488758, 557608.082100000232458 ], [ 259217.534800000488758, 557608.082100000232458 ] ] ] ] } }

My R-script looks as follows:

setwd(".................")

library(cbsodataR)
library(tidyverse)
library(sf)
library(ggplot2)
library(plotly)
library(viridis)

Find out which columns are available

metadata <- cbs_get_meta("85318NED")
print(metadata$DataProperties$Key)

Om te kijken hoe de hele dataset eruit ziet:

#checkdata <- cbs_get_data("85318NED")

Download birth rates and delete spaces from regional identifiers

data <- cbs_get_data("85318NED",
select=c("WijkenEnBuurten","Koopwoningen_40")) %>%
mutate(WijkenEnBuurten = str_trim(WijkenEnBuurten),
Koopwoningen = Koopwoningen_40)

options(stringsAsFactors = FALSE)

municipalBoundaries <- st_read("cbsgebiedsindelingen2022.gpkg")

st_layers("cbsgebiedsindelingen2022.gpkg")

municipalBoundaries <- st_read("cbsgebiedsindelingen2022.gpkg",
layer = "wijk_gegeneraliseerd")

Link data from Statistics Netherlands to geodata

data <-
municipalBoundaries %>%
left_join(data, by=c(statcode="WijkenEnBuurten"))

Create a thematic map

data %>%
filter(gm_code == "GM0363") %>% #VOEG DEZE CODE TOE (HAAL # WEG) WANNEER JE WILT FILTEREN OP EEN SPECIFIEKE GEMEENTE
ggplot() +
geom_sf(aes(fill = Koopwoningen)) +
scale_fill_viridis_c() +
labs(title = "Percentage koopwoningen per wijk, 2022", fill = "") +
theme_void()

make interactive

data_filtered <- data %>%
filter(gm_code == "GM0363")

kaart <- ggplot(data = data_filtered) +
geom_sf(aes(fill = Koopwoningen, text = statnaam)) +
scale_fill_viridis_c(option = "cividis", direction = -1) + # wijzig kleuroptie tussen aanhalingstekens
labs(title = "Percentage koopwoningen per wijk, 2022", fill = "") +
theme_void()

convert ggplot2 to plotly-object

interactivemap <- ggplotly(kaart)

plot interactive map

interactivemap

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.