Comments (2)
I was able to figure out the order using a manual approach. But now having trouble with getting opacity.
my_colors = bind_cols(rate_cat = factor(levels(df$rate_cat)), colors = c("#fecc5c","#fd8d3c","#f03b20","#bd0026","#51087e"))
df2 <- left_join(df, my_colors)
l1 <- legend_element(
variables = levels(df$rate_cat),
colours = c("#fecc5c","#fd8d3c","#f03b20","#bd0026","#51087e"),
colour_type = "fill",
variable_type = "category",
title = "Eviction rate"
)
ml <- mapdeck_legend(l1)
mapdeck(token = key, style = mapdeck_style("light")) %>%
add_polygon(
data = df2,
fill_colour = "colors",
# fill_colour = "rate_cat",
tooltip = "V1",
fill_opacity = .5,
legend = ml
)
from mapdeck.
The opacity issue relates to #292 where I needed to add the opacity to the hex value. Final code and closing this issue.
library(tigris)
library(mapdeck)
library(dplyr)
df <-
counties(state = "OR") %>%
bind_cols(
as.data.frame(matrix(runif(n=36, min=0, max=.25), nrow=36))
) %>%
mutate(rate_cat =
factor(
case_when(
V1 == 0 ~ "0%",
V1 > 0 & V1 < .021 ~ "0.1% - 2%",
V1 >= .021 & V1 < .061 ~ "2.1% - 6%",
V1 >= .061 & V1 < .121 ~ "6.1% - 12%",
V1 >= .121 ~ paste0("12.1% - ", scales::percent(max(V1, na.rm = TRUE), accuracy = .1)
)
),
levels = c("0%", "0.1% - 2%", "2.1% - 6%", "6.1% - 12%", paste0("12.1% - ", scales::percent(max(V1, na.rm = TRUE), accuracy = .1))
)
)
)
my_colors <-
bind_cols(
rate_cat = factor(levels(df$rate_cat)),
colors = c("#fecc5c50","#fd8d3c50","#f03b2050","#bd002650","#51087e50"),
opacity = rep(.5, 5)
)
df2 <- left_join(df, my_colors)
l1 <- legend_element(
variables = levels(df$rate_cat),
colours = c("#fecc5c50","#fd8d3c50","#f03b2050","#bd002650","#51087e50"),
colour_type = "fill",
variable_type = "category",
title = "Eviction rate"
)
ml <- mapdeck_legend(l1)
mapdeck(token = key, style = mapdeck_style("light")) %>%
add_polygon(
data = df2,
fill_colour = "colors",
tooltip = "V1",
legend = ml
)
from mapdeck.
Related Issues (20)
- add_polygon (and similar) crash using Rstudio when fill_colour is not blank on Windows HOT 47
- Adding more than one Mapbox style layer? HOT 5
- mapdeck install requires spatialwidget 0.2.4 ? HOT 1
- R Session Aborted during Mapdeck call HOT 2
- Empty Geometries cause issues witih colours HOT 1
- Dragging Javascript errors HOT 3
- Custom tile layer (slippy map) HOT 1
- mapdeck crashing in windows R 4.3.1 ... but not in R 4.1.3 HOT 1
- clear_bitmap() not working HOT 2
- Mapdeck inside golem shinyapp does not update! HOT 6
- add_text: --> Error: Must supply `x`, `y` and `text` attributes HOT 1
- Cesium Troubles HOT 6
- onClick events don't return layerId HOT 1
- Map crashes when hidden in multitab shiny app HOT 9
- Support for updating pitch/zoom/bearing without specifying the location HOT 3
- quarto tabset and mapdeck HOT 7
- geoarrow + mapdeck HOT 2
- crosstalk support
- Return coordinates with map click event HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mapdeck.