Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wangshiming opened this issue May 18, 2024 · 1 comment
Open

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

wangshiming opened this issue May 18, 2024 · 1 comment

Comments

@wangshiming
Copy link

wangshiming commented May 18, 2024

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_node_rect(
aes(xmin= xmin + (i-1) * space,
xmax= xmin + i * space,
fill=I(get(paste0('color_', i))),
filter=type=="ortholog"))
}

tem_plot

@wangshiming
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant