labels en municipio

87 views
Skip to first unread message

abitun...@gmail.com

unread,
Jul 24, 2019, 2:32:24 PM7/24/19
to mxmaps
Hola Diego, 
Estoy haciendo un zoom por estado y quiero ponerle a cada municipio su label. 
Estaba intentando usar esto que viene en tu página: 
p +
  geom_text_repel(data = df_mxstate, aes(lon, lat, label = state_abbr), size = 3,
                  box.padding = unit(0.1, 'lines'), force = 0.1)
pero no tengo éxito. Para ponerlas labels también debo usar longitud y latitud?
Saludos, 
Abigail

Diego Valle-Jones

unread,
Jul 24, 2019, 6:16:44 PM7/24/19
to mxmaps
Hola Abigail,

Para ponerle labels a los municipios también puedes usar la latitud y longitud de la cabecera de cada uno de los municipios que se encuentra en el data.frame df_mxmunicipio

library("mxmaps")
library
("ggrepel")

df_mxmunicipio$value
<-  df_mxmunicipio$indigenous / df_mxmunicipio$pop * 100
chih
<- subset(df_mxmunicipio, state_name %in% c("Chihuahua"))
p
<- mxmunicipio_choropleth(df_mxmunicipio, num_colors = 1,
                       zoom
= chih$region,
                       title
= "Percentage of the population that self-identifies\nas indigenous in Chihuahua",
                       show_states
= FALSE,
                       legend
= "%")

labels
<- chih
labels$group
<- NA
labels
<- subset(labels, pop > 1e05)
p
+
  geom_text_repel
(data = labels,
                  aes
(long, lat, label = municipio_name),
                  nudge_x
= .1,
                  nudge_y
= .7) +
  geom_point
(data = labels,
             aes
(long, lat),
             color
= "#d6604d",
             size
= 1)


Rplot.png
Reply all
Reply to author
Forward
0 new messages