Skip to content

Instantly share code, notes, and snippets.

@cpsievert cpsievert/ggplotly-sf.R
Last active Dec 18, 2018

What would you like to do?
# devtools::install_github("ropensci/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))) +
# use highlight function to draw polygon outline on hover
ggplotly(p, tooltip = "text") %>%
opacityDim = 1,
selected = attrs_selected(line = list(color = "black"))

This comment has been minimized.

Copy link
Owner Author

cpsievert commented Apr 27, 2017


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.