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
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.