Last active
December 18, 2018 13:14
-
-
Save cpsievert/eca3ff3eba67ab6b4719c748dafd5c4a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# devtools::install_github("ropensci/plotly") | |
library(plotly) | |
nc <- sf::st_read(system.file("shape/nc.shp", package = "sf")) | |
# shared data will make the polygons "query-able" | |
ncsd <- crosstalk::SharedData$new(nc) | |
p <- ggplot(ncsd) + | |
geom_sf(aes(fill = AREA, text = paste0(NAME, "\n", "FIPS: ", FIPS))) + | |
ggthemes::theme_map() | |
# use highlight function to draw polygon outline on hover | |
ggplotly(p, tooltip = "text") %>% | |
highlight( | |
"plotly_hover", | |
opacityDim = 1, | |
selected = attrs_selected(line = list(color = "black")) | |
) |
Author
cpsievert
commented
Apr 27, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment