r - Keep customized colors with geom_polygon() -
i have plotted map of france customized colors map()
:
map(database="france", fill=true, col=color)
results :
(don't mind 2 errors)
and want put map projection of lambert using ggplot2
package :
head(fortify(carte_france)) ggplot(map('france'), aes(long, lat, group = group)) + geom_polygon(col = 1) + coord_map(projection = "lambert", parameters = c(lat0 = 41.366005 , lat1 = 51.097523))
however gives me :
i know dark colours comes arg fill
geom_polygon()
there way tell function geom_polygon()
not use arg fill
or keep colors have put before ?
vector of colours, color
:
c("yellowgreen", "yellowgreen", "yellowgreen", "yellowgreen", "gold1", "sienna3", "yellowgreen", "yellowgreen", "sienna3", "gold1", "gold1", "gold1", "sienna3", "sienna3", "gold1", "dodgerblue2", "dodgerblue2", "dodgerblue2", "gold1", "dodgerblue2", "sienna3", "dodgerblue2", "burlywood2", "dodgerblue2", "palevioletred4", "dodgerblue2", "palevioletred4", "dodgerblue2", "palevioletred4", "palevioletred4", "gold1", "palevioletred4", "gold1", "darkorchid4", "gold1", "darkorchid4", "palevioletred4", "green4", "cyan4", "gold1", "palevioletred4", "burlywood2", "green4", "green4", "cyan4", "darkorchid4", "green4", "burlywood2", "palevioletred4", "burlywood2", "green4", "green4", "palevioletred4", "palevioletred4", "palevioletred4", "green4", "burlywood2", "olivedrab2", "green4", "olivedrab2", "darkorchid4", "darkorchid4", "cyan4", "darkorchid4", "cyan4", "cyan4", "olivedrab2", "olivedrab2", "olivedrab2", "cyan4", "cyan4", "olivedrab2", "cyan4", "olivedrab2", "olivedrab2", "cyan4", "cyan4", "olivedrab2", "olivedrab2", "olivedrab2", "cyan4", "cyan4", "cyan4", "cyan4", "orange2", "orangered1", "orangered1", "orangered1", "olivedrab2", "orange2", "olivedrab2", "orangered1", "orange2", "orangered1", "orange2", "orange2", "orangered1", "orangered1", "orangered1", "orange2", "orangered1", "orange2", "orangered1", "olivedrab2", "orangered1", "orangered1", "orangered1", "orangered1", "orange2", "orange2", "orange2", "chartreuse3", "orangered1", "chartreuse3")
first, should use map_data
create dataset in format ggplot maps library map. in case, not have these white dots on map.
defined order of colors based on order of polygons in map
function, created table left joining map_data
.
# polygon order map map_france <- map(database="france", fill=true) # create dataframe department , corresponding colors names_col <- data.frame( region = map_france$names, col_dpt = c("yellowgreen", "yellowgreen", "yellowgreen", "yellowgreen", "gold1", "sienna3", "yellowgreen", "yellowgreen", "sienna3", "gold1", "gold1", "gold1", "sienna3", "sienna3", "gold1", "dodgerblue2", "dodgerblue2", "dodgerblue2", "gold1", "dodgerblue2", "sienna3", "dodgerblue2", "burlywood2", "dodgerblue2", "palevioletred4", "dodgerblue2", "palevioletred4", "dodgerblue2", "palevioletred4", "palevioletred4", "gold1", "palevioletred4", "gold1", "darkorchid4", "gold1", "darkorchid4", "palevioletred4", "green4", "cyan4", "gold1", "palevioletred4", "burlywood2", "green4", "green4", "cyan4", "darkorchid4", "green4", "burlywood2", "palevioletred4", "burlywood2", "green4", "green4", "palevioletred4", "palevioletred4", "palevioletred4", "green4", "burlywood2", "olivedrab2", "green4", "olivedrab2", "darkorchid4", "darkorchid4", "cyan4", "darkorchid4", "cyan4", "cyan4", "olivedrab2", "olivedrab2", "olivedrab2", "cyan4", "cyan4", "olivedrab2", "cyan4", "olivedrab2", "olivedrab2", "cyan4", "cyan4", "olivedrab2", "olivedrab2", "olivedrab2", "cyan4", "cyan4", "cyan4", "cyan4", "orange2", "orangered1", "orangered1", "orangered1", "olivedrab2", "orange2", "olivedrab2", "orangered1", "orange2", "orangered1", "orange2", "orange2", "orangered1", "orangered1", "orangered1", "orange2", "orangered1", "orange2", "orangered1", "olivedrab2", "orangered1", "orangered1", "orangered1", "orangered1", "orange2", "orange2", "orange2", "chartreuse3", "orangered1", "chartreuse3") )
then can join dataframe data created map_data
, call colour vector ggplot.
# map in correct format ggplot # , join correspondance of colors carte_france <- map_data('france') %>% left_join(names_col) # plot ggplot(carte_france, aes(long, lat, group = group)) + geom_polygon(col = 1, fill = carte_france$col_dpt) + coord_map(projection = "lambert", parameters = c(lat0 = 41.366005 , lat1 = 51.097523))
for information, on website of ign (http://professionnels.ign.fr/geofla), can download map of french departements, information on region. in case, easier create vector of colors based on region name...
Comments
Post a Comment