How to get a legend from genoplotR?
1
0
Entering edit mode
10 weeks ago

I have a genome that I would like to compare to its reference. I have used genoplotR as implemented within fastANI and I got a decent graph:

enter image description here

Is it possible to add a scale to give a sense of the colors? In the manual, scale=TRUE by default and legend is still not implemented...

Thank you

visualization fastANI genome genoplotR • 6.9k views
ADD COMMENT
0
Entering edit mode

Hi,

I'm not familiar with this package or function, but from the function documentation that you had provided in the link, it says about the parameter legend: Yet unimplemented.

ADD REPLY
0
Entering edit mode
13 days ago
Kevin Blighe ★ 90k

The legend parameter in the plot_gene_map function from genoplotR is not implemented, as stated in the documentation. The scale parameter refers to a genomic position scale, not a color scale. Since genoplotR uses the grid graphics system, you can manually add a color legend by creating an additional viewport and drawing a gradient bar or discrete color squares using grid functions.

If your plot uses a global color scheme based on a comparison metric such as sequence identity, you can add a continuous color legend with code similar to the following. Adjust the colors and values to match your global_color_scheme argument.

library(grid)
library(genoPlotR)

# Your original plot call, with plot_new = FALSE to avoid new page
pushViewport(viewport(layout = grid.layout(1, 2, widths = unit(c(0.8, 0.2), "npc"))))
pushViewport(viewport(layout.pos.col = 1))
plot_gene_map(dna_segs = your_dna_segs, comparisons = your_comparisons, plot_new = FALSE, ...)  # Your parameters here
upViewport()

# Add legend in second column
pushViewport(viewport(layout.pos.col = 2))
# Example for a blue-red gradient legend assuming values from 0 to 100
col_fun <- colorRampPalette(c("blue", "red"))
n <- 100
y <- seq(0, 1, length = n)
grid.rect(x = 0.5, y = y, width = 0.2, height = 1/n, gp = gpar(fill = col_fun(n), col = NA), just = "center")
grid.text(c("0", "50", "100"), x = 0.8, y = c(0, 0.5, 1), just = "left", gp = gpar(cex = 0.8))
grid.text("Identity (%)", x = 0.5, y = 1.1, just = "center", gp = gpar(cex = 0.8))
upViewport(2)

This creates a side legend. For discrete colors, replace the gradient with individual rectangles. Test this in your FastANI visualization script by modifying visualize.R accordingly.

Kevin

ADD COMMENT

Login before adding your answer.

Traffic: 3488 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6