ggcoverage icon indicating copy to clipboard operation
ggcoverage copied to clipboard

Is it possible to highlight specific genes in geom_gene?

Open bvaldebenitom opened this issue 9 months ago • 2 comments

Hi!

Thanks again for developing and maintaining this excellent tool.

I'm trying to do new plots where I want to color a specific gene in one color, and all the others in the region with another color. I tried adding geom_gene(gtf.gr=gtf,fill.color.by="gene_name",plot.height=0.15) but then I get

Error in geom_gene(gtf.gr = gtf, fill.color.by = "gene_name", plot.height = 0.15) : 
  unused argument (fill.color.by = "gene_name")

Would this be possible, or the color.by option is only meant for coloring genes according to their strands?

EDIT: I was incorrectly typing the parameter as fill.color.by. I solved the issue by first creating a named vector with the gene names, specifying their color, like this: color_dict <- c("gene1" = "color1", ..., "geneN"="colorN") and properly setting the parameters in geom_gene: geom_gene(gtf.gr=gtf,color.by="gene_name",fill.color=color_dict,plot.height=0.15)

Using black and red, I got this:

Image

Leaving this open in case there is a more elegant way to achieve this. If this is the intended way, I would suggest to expand the documentation to further clarify this, as I realized the possible options by checking the source code. In particular, the column names in line 192 of geom_gene: used.gtf.columns <- c("seqnames", "start", "end", "strand", "type", "gene_name")

Thanks again.

bvaldebenitom avatar Mar 17 '25 13:03 bvaldebenitom

Great you could solve it! I see you're coming from the python world, judging from the effort to use a dict :-) However in ggplot (the underlying plotting system for ggcoverage) you can actually use data frames to pass all information efficiently you want to plot, without having to specify dicts. However, I noticed that the extra metadata columns are filtered out, as you also wrote in your post. This needs to be fixed, the user should be able to use any metadata column to color genes the way they wish.

I will try a fix as soon as I have time.

m-jahn avatar Mar 18 '25 08:03 m-jahn

Thanks for the kind words, and prompt answer as usual!

I look forward to updates in ggcoverage. Thanks for maintaining it!

bvaldebenitom avatar Mar 24 '25 16:03 bvaldebenitom