Open wangshiming opened 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
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
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