Skip to content

Instantly share code, notes, and snippets.

@cpsievert
Last active December 18, 2018 13:14
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
library(sf)
library(dplyr)
library(albersusa)
library(crosstalk)
library(plotly)
usa <- usa_sf("laea")
# st_centroid gets the center POINT of polygons
uscenter <- usa %>%
st_centroid() %>%
mutate(
x = sapply(geometry, "[[", 1),
y = sapply(geometry, "[[", 2)
) %>%
SharedData$new()
p <- ggplot() +
geom_sf(data = usa, aes(fill = pop_2010, text = paste("Population", pop_2010))) +
geom_text(
data = uscenter, alpha = 0,
aes(x, y, label = name, text = "Click to label me")
)
ggplotly(p, tooltip = "text") %>%
highlight(
persistent = TRUE,
selected = attrs_selected(
hoverinfo = "none",
textfont = list(color = "black")
)
)
@edzer
Copy link

edzer commented Jan 31, 2018

Confirmed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment