Cambiar colores

28 views
Skip to first unread message

Manuel Pérez Aguirre

unread,
May 2, 2024, 4:29:44 AM5/2/24
to mxmaps
Hola Diego
Muchas gracias por este foro
Estoy ploteando algo muy sencillo


mxmunicipio_choropleth(sina_map2020,
                       num_colors = 1,
                       title = "Percentage of the population that speaks\nan indigenous language",
                       legend = "%")

Pero quiero cambiarle los colores, x default lanza azul
Qué hago?

Diego Valle-Jones

unread,
May 2, 2024, 8:32:01 AM5/2/24
to mxmaps
Hola Manuel, eso lo podrías hacer con algo así (adaptado de https://www.diegovalle.net/mxmaps/articles/municipios.html)

library(mxmaps)
library(viridis)
library(scales)


gg = MXMunicipioChoropleth$new(sina_map2020)
gg$title <- "Percentage of the population that speaks\nan indigenous language"
gg$set_num_colors(1)
gg$ggplot_scale <- scale_fill_viridis("percent",
                                      labels = percent)
gg$render()

Manuel Pérez Aguirre

unread,
May 2, 2024, 11:26:30 AM5/2/24
to mxmaps
Pero me refería más a cambiar el color base. A verde, rojo, púrpura, a ver cuál me gusta más

Muchas gracias de antemano

Diego Valle-Jones

unread,
May 2, 2024, 11:38:27 AM5/2/24
to mxmaps
Eso lo puedes hacer con scale_fill_distiller() y usar una de las paletas de colores de colorbrewer (https://r-graph-gallery.com/38-rcolorbrewers-palettes.html)

library(mxmaps)
library(viridis)
library(scales)
library(ggplot2)

df_mxmunicipio_2020$value <-  df_mxmunicipio_2020$indigenous_language /
  df_mxmunicipio_2020$pop
gg = MXMunicipioChoropleth$new(df_mxmunicipio_2020)

gg$title <- "Percentage of the population that speaks\nan indigenous language"
gg$set_num_colors(1)
gg$ggplot_scale <- scale_fill_distiller(palette = "Greens")
gg$render()


Reply all
Reply to author
Forward
0 new messages