noriakis / ggkegg

Analyzing and visualizing KEGG information using the grammar of graphics
https://noriakis.github.io/software/ggkegg
MIT License
201 stars 16 forks source link

How to make the function "geom_node_rect" work in a loop #29

Open wangshiming opened 1 month ago

wangshiming commented 1 month ago

g <- pathway("ko00520") V(g)$color_1 <- colorRampPalette(RColorBrewer::brewer.pal(5,"Set1"))(length(V(g))) V(g)$color_2 <- colorRampPalette(RColorBrewer::brewer.pal(5,"Set2"))(length(V(g))) V(g)$color_3 <- colorRampPalette(RColorBrewer::brewer.pal(5,"PuOr"))(length(V(g))) V(g)$color_4 <- colorRampPalette(RColorBrewer::brewer.pal(5,"Paired"))(length(V(g)))

V(g)$space <- V(g)$width/4

tem_plot = ggraph(g, x=x, y=y) for (i in c(1:4)){ tem_plot = tem_plot + geom_noderect( aes(xmin= xmin + (i-1) space, xmax= xmin + i space, fill=I(get(paste0('color', i))), filter=type=="ortholog")) }

tem_plot

wangshiming commented 1 month ago

I also tried the technique by passing '.data' variable mention by: https://stackoverflow.com/questions/15987367/how-to-add-layers-in-ggplot-using-a-for-loop