0

I would like to map some data on residues of pesticides in surface water. I have a dataset with different pesticides, and for each pesticide, different monitoring stations with multiple residues for some years. something like this:

PARAM station year values
A stat1 2009 0.01
A stat2 2009 0.05
A stat1 2010 0.10
A stat3 2010 0.04
A stat1 2011 0.02
A stat2 2011 0.01
B stat1 2009 0.01
B stat3 2009 0.22
B stat1 2010 0.03
B stat3 2010 0.02
B stat1 2011 0.01
B stat2 2011 0.10

With the code below, I obtain a map with a number of legends equal to the number of years I have data for. Due to the fact that the legend is always the same for all the years, is there a way to collapse the numerous legends to a single one? Thanks

mx <- tm_shape(World)+
                tm_view(set.view = c(9.7, 45.5, 8), view.legend.position = c("left", "top"))+
                tm_basemap("Esri.WorldTopoMap")+
                tm_borders("white", lwd = .5) +
                tm_shape(pesticides) +
                tm_dots(
                  col="values",
                  legend.hist = TRUE,
                  size=0.3,
legend.show =T,
                  popup.vars=c("Id Station"="station",
                               "Valore"= "values",
                               "Substance" = "PARAM")
                )+
                tm_facets( by= "year",
                           nrow = 9,
                           sync = TRUE,
                           as.layers = T,
                           drop.units = T)

You are right! you can find my example at this shiny.io website https://icpsxfiles.shinyapps.io/StOv_example/ as you can see in the residue map there are multiple legends according to the number of years I have data for each parameter. Another thing I noticed is that according to the first graph, the one with the boxplots, the distribution of data is of course different from one year to another, so the legends should modify accordingly.. or not? In this shiny example I set legend.show = TRUE

  • 3
    Without sample data I won't make an example, but if the legends are identical, you could use `legend.show = FALSE` in all but one layers. Or, set the same breaks and colours if legends are different and do the same. – hugh-allan Sep 27 '21 at 10:25
  • Please trim your code to make it easier to find your problem. Follow these guidelines to create a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). – Community Sep 28 '21 at 00:46

0 Answers0