Skip to content

Commit

Permalink
add shiny image
Browse files Browse the repository at this point in the history
  • Loading branch information
diegovalle committed Nov 19, 2021
1 parent 6d56d09 commit e72c932
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
28 changes: 28 additions & 0 deletions vignettes/articles/leaflet_states.Rmd
Expand Up @@ -30,3 +30,31 @@ mxstate_leaflet(df_mxstate_2020,
transform = function(x) {100 * x})) %>%
addProviderTiles("CartoDB.Positron")
```


You can also create maps with categorical variables by first converting the
variables to integers and using the `colors` and `labels` parameters to `addLegend` to assign the colors to each level in the variable.


```{r}
library(mxmaps)
library(leaflet) # for colorBin
library(scales) # needed for comma
df_mxstate_2020$value2 <- factor(sample(c("a", "b", "c", "d", "e"), 32, replace = TRUE))
df_mxstate_2020$value <- as.integer(df_mxstate_2020$value2)
pal <- colorBin(rainbow(5), domain = as.integer(factor(df_mxstate_2020$value2)))
mxstate_leaflet(df_mxstate_2020,
pal,
~ pal(value),
~ sprintf("State: %s<br/>Percent Afro-Mexican: %s",
state_name, comma(value))) %>%
addLegend(position = "bottomright",
colors =c(rainbow(5)),
labels= c("a", "b","c","d", "e"),
title = "categoría"
) %>%
addProviderTiles("CartoDB.Positron")
```
2 changes: 1 addition & 1 deletion vignettes/articles/shiny.Rmd
Expand Up @@ -11,7 +11,7 @@ knitr::opts_chunk$set(echo = TRUE,
```

```{r echo=FALSE, out.width='100%'}
knitr::include_graphics('https://github.com/diegovalle/mxmaps/raw/master/vignettes/articles/homicides_shiny.png')
knitr::include_graphics('homicides_shiny.png')
```

You can also use the data that comes with the package to create interactive webapps with shiny.
Expand Down

0 comments on commit e72c932

Please sign in to comment.