Home > OS >  Can I change the colour of a country map plotted in R using
Can I change the colour of a country map plotted in R using

Time:11-18

I have plotted the map of South America using

library(maps) library(ggplot2) library(dplyr)

p=c("Brazil", "Argentina", "Chile", "Uruguay", "Paraguay", "Ecuador", "Peru", "Venezuela",
         "Colombia", "Bolivia")

mp<-map_data("world", region=p) 

mlola <- mp %>%  group_by(region) %>% 
  summarize(mlo= mean(long), mla=mean(lat))


ggplot(mapa_paises,aes( x= long, y = lat, group=group, fill=region))  
  geom_polygon( ) 
  theme(panel.background = element_rect(fill=NA))

Now, I need to plot it using a blue scale, using Bluges. I have tried to add it as follows:

library(maps)
library(ggplot2)
library(dplyr)
library(RColorBrewer)



    p=c("Brazil", "Argentina", "Chile", "Uruguay", "Paraguay", "Ecuador", "Peru", "Venezuela",
             "Colombia", "Bolivia")
    
    mp<-map_data("world", region=p) 
    
    mlola <- mp %>%  group_by(region) %>% 
      summarize(mlo= mean(long), mla=mean(lat))
    
    
    ggplot(mapa_paises,aes( x= long, y = lat, group=group, fill=region))  
      geom_polygon(aes(color="Bluges")) 
      theme(panel.background = element_rect(fill=NA))

This, however,doesn't seem to do anything. I have checked the help of geom_poligon, but I cannot see how to do it.

CodePudding user response:

Do you mean something like that?

library(maps)
library(ggplot2)
library(dplyr)
library(RColorBrewer)

p=c("Brazil", "Argentina", "Chile", "Uruguay", "Paraguay", "Ecuador", "Peru", "Venezuela",
    "Colombia", "Bolivia")

mp<-map_data("world", region=p) 

mlola <- mp %>%  group_by(region) %>% 
  summarize(mlo= mean(long), mla=mean(lat))

#changed the dataset to mp
ggplot(mp,aes( x= long, y = lat, group=group, fill=region))  
  geom_polygon(aes(fill=region),
               color = "black") 
  scale_fill_brewer(palette = "Blues") 
  theme(panel.background = element_rect(fill=NA))
#> Warning in RColorBrewer::brewer.pal(n, pal): n too large, allowed maximum for palette Blues is 9
#> Returning the palette you asked for with that many colors

Created on 2022-11-17 with reprex v2.0.2

This palette (Blues) is not advised because it has just 9 levels, and we are trying to plot 10 countries.

  • Related