Last active
December 18, 2018 13:14
-
-
Save cpsievert/fa56bd89122e395803f30602b774dbe1 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
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") | |
) | |
) |
Author
cpsievert
commented
Apr 27, 2017
Really nice! The plot I get after copy & paste the code has a different aspect ratio, making it less useful:
Also, 28 warnings of this kind:
Warning messages:
1: In FUN(X[[i]], ...) :
is.na() applied to non-(list or vector) of type 'language'
> devtools::session_info()
Session info -------------------------------------------------------------------
setting value
version R version 3.4.0 (2017-04-21)
system x86_64, linux-gnu
ui X11
language en_US
collate en_US.UTF-8
tz Europe/Berlin
date 2017-05-30
Packages -----------------------------------------------------------------------
package * version date source
albersusa * 0.3.0 2017-05-30 Github (hrbrmstr/albersusa@82220d3)
assertthat 0.2.0 2017-04-11 CRAN (R 3.4.0)
colorspace 1.3-2 2016-12-14 CRAN (R 3.4.0)
crosstalk * 1.0.0 2016-12-21 cran (@1.0.0)
data.table 1.10.4 2017-02-01 CRAN (R 3.4.0)
DBI 0.6-1 2017-04-01 CRAN (R 3.4.0)
devtools 1.12.0 2016-12-05 CRAN (R 3.4.0)
digest 0.6.12 2017-01-27 CRAN (R 3.4.0)
dplyr * 0.5.0 2016-06-24 CRAN (R 3.4.0)
foreign 0.8-67 2016-09-13 CRAN (R 3.3.1)
ggplot2 * 2.2.1.9000 2017-05-30 Github (tidyverse/ggplot2@f4398b6)
gtable 0.2.0 2016-02-26 CRAN (R 3.4.0)
htmltools 0.3.6 2017-04-28 cran (@0.3.6)
htmlwidgets 0.8 2016-11-09 CRAN (R 3.4.0)
httpuv 1.3.3 2015-08-04 CRAN (R 3.4.0)
httr 1.2.1 2016-07-03 CRAN (R 3.4.0)
jsonlite 1.4 2017-04-08 CRAN (R 3.4.0)
labeling 0.3 2014-08-23 CRAN (R 3.4.0)
lattice 0.20-35 2017-03-25 CRAN (R 3.3.3)
lazyeval 0.2.0 2016-06-12 CRAN (R 3.4.0)
magrittr 1.5 2014-11-22 CRAN (R 3.4.0)
maptools 0.9-2 2017-03-25 CRAN (R 3.4.0)
memoise 1.1.0 2017-04-21 CRAN (R 3.4.0)
mime 0.5 2016-07-07 CRAN (R 3.4.0)
munsell 0.4.3 2016-02-13 CRAN (R 3.4.0)
plotly * 4.7.0 2017-05-28 CRAN (R 3.4.0)
plyr 1.8.4 2016-06-08 CRAN (R 3.4.0)
purrr 0.2.2.9000 2017-04-28 Github (tidyverse/purrr@4ab056f)
R6 2.2.1 2017-05-10 cran (@2.2.1)
Rcpp 0.12.11.1 2017-05-30 Github (RcppCore/Rcpp@ef4e9c5)
rgdal 1.2-7 2017-04-25 cran (@1.2-7)
rgeos 0.3-23 2017-04-06 CRAN (R 3.4.0)
rlang 0.1.1 2017-05-18 cran (@0.1.1)
scales 0.4.1 2016-11-09 CRAN (R 3.4.0)
sf * 0.5-0 2017-05-28 local
shiny 1.0.3 2017-04-26 CRAN (R 3.4.0)
sp 1.2-5 2017-05-22 local
tibble 1.3.3 2017-05-30 Github (tidyverse/tibble@b2275d5)
tidyr 0.6.1 2017-01-10 CRAN (R 3.4.0)
udunits2 0.13 2016-11-17 CRAN (R 3.4.0)
units 0.4-5 2017-05-24 local
viridisLite 0.2.0 2017-03-24 CRAN (R 3.4.0)
withr 1.0.2 2016-06-20 CRAN (R 3.4.0)
xtable 1.8-2 2016-02-05 CRAN (R 3.4.0)
yaml 2.1.14 2016-11-12 CRAN (R 3.4.0)
</details>
Thanks @edzer, this should be fixed now.
Confirmed!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment