This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Modify color in pie charts on a geographical map

Hi, I have generated the pie charts on a geographical map using ggplot following the tutorial (https://towardsdatascience.com/using-ggplot-to-plot-pie-charts-on-a-geographical-map-bb54d22d6e13),

# Using map_data()
worldmap <- map_data ("world")
colours_group = c("#EE2700", "#5EFF01","#94569d", "#3404FE","#FBFF00", "#F200FE", "#6AFDFF", "#F29A03","#7F415C", "#F3985D")
mapplot1 <- ggplot(worldmap) +
  geom_map(data = worldmap, map = worldmap, aes(x=long, y=lat, map_id=region), color = "black", fill = NA) +
  geom_scatterpie(aes(x=longitude, y=latitude, group = Countries, r = multiplier*6),
                  data = final_data, cols = colnames(final_data[,c(2:11)])) + 
  scale_fill_manual("vunrisk", values = colours_group)

mapplot1 + theme(axis.title.x = element_blank(), axis.title.y = element_blank(), axis.text.x =element_blank(), axis.ticks.x = element_blank(), axis.text.y = element_blank(), axis.ticks.y = element_blank(), panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
                 panel.background = element_blank(), axis.line = element_blank())

I am trying to replace the default colours with the following colours but its not working:

colours = c("#EE2700", "#5EFF01","#94569d", "#3404FE","#FBFF00", "#F200FE", "#6AFDFF", "#F29A03","#7F415C", "#F3985D")
ggplot

1 answer

I have designed the solution. I have specified the lists of colors:

colours_group = c("#EE2700", "#5EFF01","#94569d", "#3404FE","#FBFF00", "#F200FE", "#6AFDFF", "#F29A03","#7F415C", "#F3985D")

and then I added replaced the default colors using:

scale_fill_manual("vunrisk", values = colours_group)

I have incorporated the solution the question

Log in to answer this question.