Giter VIP home page Giter VIP logo

Comments (2)

timathomas avatar timathomas commented on June 11, 2024

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.

timathomas avatar timathomas commented on June 11, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.