thackl / gggenomes

A grammar of graphics for comparative genomics
https://thackl.github.io/gggenomes/
Other
579 stars 64 forks source link

Changing color of links #123

Closed Marlon751 closed 1 year ago

Marlon751 commented 2 years ago

Hi. I was wondering is it possible to change the color of the geom_link(). I would like to achieve something like this:

question_gggenome

thackl commented 2 years ago

Hi, not sure I fully understand - might be useful to post some of your code. In general, it is definitely possible to change the fill/color of links, for example:

gggenomes(emale_genes) %>% add_clusters(emale_cogs) +
  geom_link(aes(fill=cluster_id))

image

Assuming you know that and tried something with add_clusters(), one issue you might have come across is that the following doesn't work, i.e. metadata associated with clusters is not added to links. Then you would be quite right, that should work. I'll try to add that soon.

emale_cogs
gggenomes(emale_genes) %>% add_clusters(emale_cogs) +
  geom_link(aes(fill=cluster_size))

### FAILS

A quick workaround could be to replace cluster_id in your cluster data.frame with whatever labels you want to color your links by:

# just randomly assign for coloring example
emale_cogs2 <- emale_cogs %>%
  mutate(cluster_id = sample(c("many", "single"), length(cluster_id), replace = T))

gggenomes(emale_genes) %>% add_clusters(emale_cogs2) +
  geom_link(aes(fill=cluster_id))

image

Marlon751 commented 2 years ago

Thank you very much!