Question: issue with node colors while making a popgraph using ggplot/popgraph
1
gravatar for Dracaena
10 months ago by
Dracaena40
Dracaena40 wrote:

Hi guys,

I have ran into some troubles making a population graph using popgraph/ggplot in R. More specifically, I want each module in a different color and I try to do so using geom_edgeset(color = module) and scale_colors_manual( values = nodecolors). What happens is that every node just colors black. How do I solve this issue?

Here is the script I used:

p <- ggplot()
world <- map_data("world") #add a base map = bottom layer
p <- p + geom_polygon(data = world, aes(x=long, y = lat, group=group), fill="lightgrey")


nodecolors <- c("module1" = "yellow", "module2"="green", "module3"="blue", "module4" = "purple") #named chr for colors
p <- p +  geom_edgeset( aes(x=longitude,y=latitude), combo, color="darkgrey") #combo is a popgraph/igraph object, an edge matrix decorated with information for each population (such as to which module it belongs)
p <- p +  geom_nodeset(aes(x=longitude,y=latitude,color = as.factor(module)), combo, size=mod$nalleles/15) 
p <- p +  theme(panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(),
        panel.background = element_blank(), axis.line = element_line(colour = "black")) #remove bg
p <- p + scale_color_manual(values = nodecolors)
p

What I get:

enter image description here

here is summary(combo) IGRAPH 43ff52a UNW- 119 615 -- + attr: name (v/c), population (v/n), module (v/n), color (v/n), connectivity (v/n), participation (v/n), | role (v/n), longitude (v/n), latitude (v/n), nalleles (v/n), Hexp (v/n), Hobs (v/n), weight (e/n)

and here is dput(head(combo):

new("dgCMatrix", i = c(2L, 4L, 5L, 0L, 3L, 2L, 0L, 5L, 0L, 4L, 
0L, 2L, 3L, 0L, 2L, 0L, 0L, 5L, 1L, 4L, 3L, 1L, 1L, 0L, 3L, 4L, 
4L, 5L, 1L, 2L, 1L, 0L, 3L, 3L, 4L, 5L, 1L, 2L, 5L, 3L, 4L, 0L, 
2L, 5L, 1L, 0L, 5L, 0L, 1L, 2L, 3L, 4L, 5L, 1L, 1L, 2L, 1L, 2L, 
3L, 3L, 5L, 3L), p = c(0L, 3L, 3L, 5L, 6L, 8L, 10L, 13L, 15L, 
16L, 18L, 20L, 21L, 21L, 21L, 21L, 22L, 23L, 24L, 26L, 26L, 28L, 
28L, 30L, 31L, 33L, 36L, 39L, 41L, 44L, 45L, 47L, 53L, 53L, 54L, 
56L, 58L, 58L, 58L, 58L, 58L, 58L, 58L, 58L, 58L, 58L, 58L, 58L, 
58L, 58L, 58L, 58L, 58L, 58L, 58L, 58L, 58L, 58L, 58L, 59L, 59L, 
59L, 59L, 59L, 59L, 59L, 59L, 59L, 59L, 59L, 59L, 59L, 59L, 59L, 
59L, 59L, 59L, 60L, 60L, 60L, 60L, 60L, 61L, 61L, 61L, 61L, 61L, 
61L, 61L, 61L, 61L, 61L, 61L, 61L, 61L, 61L, 61L, 61L, 61L, 61L, 
61L, 61L, 61L, 61L, 61L, 61L, 61L, 61L, 61L, 61L, 61L, 61L, 61L, 
61L, 61L, 62L, 62L, 62L, 62L, 62L), Dim = c(6L, 119L), Dimnames = list(
    c("SSA_Ben_Kor_2006", "SSA_Bot_Tut_2009", "SSA_Cam_Ess_2005", 
    "SSA_Con_Luk_2007", "SSA_Gha_Dal_2009", "SSA_Gha_Mam_2009"
    ), c("SSA_Ben_Kor_2006", "SSA_Bot_Tut_2009", "SSA_Cam_Ess_2005", 
    "SSA_Con_Luk_2007", "SSA_Gha_Dal_2009", "SSA_Gha_Mam_2009", 
    "SSA_Ivo_Abi_2009", "SSA_Ivo_Kor_2005", "SSA_Ivo_Sin_2009", 
    "SSA_Ken_Riu_1995", "SSA_Mal_Lil_2010", "SSA_Mau_Eas_2010", 
    "SSA_Mau_Nor_2010", "SSA_Mau_Sou_2010", "SSA_Mau_Wes_2010", 
    "SSA_Moz_Map_2009", "SSA_Moz_Mec_2008", "SSA_Moz_Mit_2008", 
    "SSA_Nig_Nig_1991", "SSA_Reu_Lig_2009", "SSA_SAf_Bon_2010", 
    "SSA_SAf_Cer_2010", "SSA_SAf_Rie_2010", "SSA_SAf_Wol_2010", 
    "SSA_Sen_Fil_2010", "SSA_Sen_Keu_2010", "SSA_Sen_Thi_2010", 
    "SSA_Sud_Gez_2009", "SSA_Sud_Sin_2009", "SSA_Tan_Kib_2009", 
    "SSA_Tog_Ago_2009", "SSA_Tog_Lom_2009", "SSA_Uga_Kaw_2005", 
    "SSA_Zam_Maz_2008", "SSA_Zam_Lus_2007", "SSA_Zam_Sia_2008", 
    "EUM_Boz_Mos_2009", "EUM_Boz_Ner_2009", "EUM_Cro_Dub_2009", 
    "EUM_Cro_Zad_2009", "EUM_Gre_Yol_2009", "EUM_Isr_Kfa_2009", 
    "EUM_Isr_Kvu_2009", "EUM_Isr_Par_2009", "EUM_Isr_Reh_2009", 
    "EUM_Isr_Nes_2009", "EUM_Ita_Sic_1998", "EUM_Ita_Met_1996", 
    "EUM_Ita_Cut_2010", "EUM_Mad_Mad_2011", "EUM_Mon_Bao_2009", 
    "EUM_Mon_Bar_2009", "EUM_Mon_Las_2009", "EUM_Mor_Mar_2009", 
    "EUM_Por_Mad_2005", "EUM_Por_Alg_2011", "EUM_Spa_Ali_2010", 
    "EUM_Spa_Alm_2010", "EUM_Spa_Cas_2010", "EUM_Spa_Val_2010", 
    "EUM_Spa_Bal_2010", "EUM_Tun_NA_NA", "EUM_Tur_Bom_2010", 
    "HAW_Haw_Haw_1991", "HAW_Haw_Kip_1991", "HAW_Haw_Kau_1991", 
    "HAW_Haw_Oah_1991", "HAW_Haw_Mau_1991", "CAM_Cos_Ala_1992", 
    "CAM_Cos_Gua_1993", "CAM_Cos_San_1956", "CAM_Cos_Pun_1992", 
    "CAM_ElS_San_1998", "CAM_Gua_San_2009", "CAM_Gua_Gua_1997", 
    "CAM_Gua_Gua_1999", "CAM_Gua_San_1990", "CAM_Gua_Ant_1990", 
    "CAM_Hon_Hon_NA", "CAM_Hon_IH_2000", "CAM_Hon_Tru_2010", 
    "CAM_Hon_Hon_1992", "CAM_Hon_Riv_2000", "CAM_Nic_Leo_2000", 
    "CAM_Nic_Man_2000", "CAM_Nic_Riv_2000", "CAM_Pan_Chi_2009", 
    "CAM_Pan_Pan_1992", "SAM_Arg_Bue_1993", "SAM_Arg_Cor_1993", 
    "SAM_Arg_Ent_1993", "SAM_Arg_San_1993", "SAM_Bol_San_2001", 
    "SAM_Bra_Per_1993", "SAM_Bra_Sao_2001", "SAM_Bra_Bah_NA", 
    "SAM_Bra_Esp_NA", "SAM_Bra_Goi_1996", "SAM_Bra_Mar_NA", "SAM_Bra_Mat_NA", 
    "SAM_Bra_Bah_1993", "SAM_Bra_Rio_NA", "SAM_Col_Ant_NA", "SAM_Ecu_Imb_1994", 
    "SAM_Ecu_Pec_1994", "SAM_Ecu_Tun_1994", "SAM_Ecu_Azu_1997", 
    "SAM_Par_Caa_2001", "SAM_Par_Par_2001", "SAM_Per_Piu_1994", 
    "SAM_Per_Can_1994", "SAM_Per_Lim_1994", "SAM_Per_Tac_1994", 
    "SAM_Ven_Ven_1992", "AUS_Aus_Per_1994", "AUS_Aus_Per_2011", 
    "AUS_Aus_Wes_2011", "AUS_Aus_Wes_2015", "AUS_Aus_Wes_2016"
    )), x = c(0.971185465, 0.959957553, 0.975074464, 0.971185465, 
0.942539513, 0.942539513, 0.959957553, 0.949675685, 0.975074464, 
0.949675685, 0.96823382, 0.951444429, 0.914758187, 0.965733122, 
0.939819285, 0.978268071, 0.968965936, 0.964925752, 0.943911656, 
0.829393223, 0.804226197, 0.957180344, 0.949150505, 0.96733028, 
0.880829749, 0.86648621, 0.884244327, 0.959141918, 0.949828392, 
0.938221117, 0.955754452, 0.957863477, 0.91340748, 0.872044799, 
0.902641888, 0.932961912, 0.933447048, 0.936548539, 0.953347082, 
0.831265914, 0.767998051, 0.971399981, 0.965990399, 0.971301897, 
0.961281417, 0.957878235, 0.943745515, 0.978540307, 0.963631678, 
0.967427473, 0.951993961, 0.952982237, 0.97494466, 0.968191119, 
0.956617658, 0.95845831, 0.962761419, 0.954156934, 0.889045916, 
0.812232525, 0.990101188, 0.768605046), factors = list())

Cheers, Pablo

ADD COMMENTlink modified 10 months ago by zx87549.7k • written 10 months ago by Dracaena40
1

May want to use these directions to add images: How to add images to a Biostars post

ADD REPLYlink written 10 months ago by GenoMax93k

Thanks! Included the image now.

ADD REPLYlink written 10 months ago by Dracaena40
1

Please provide example data dput(combo).

ADD REPLYlink written 10 months ago by zx87549.7k

Thank you! I have provided a link to the combo object

ADD REPLYlink written 10 months ago by Dracaena40
1

Link is broken, it is better to put the date in this post, no external links. Edit your post with output of dput(combo), if the data is too big, maybe try dput(head(combo)).

ADD REPLYlink written 10 months ago by zx87549.7k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1129 users visited in the last hour