tomroh / leaflegend

Provides extensions to the leaflet R package to customize legends with images, text styling, orientation, sizing, and symbology.
https://leaflegend.delveds.com
Other
34 stars 3 forks source link

Bins function does not work properly #82

Closed Agucha1986 closed 4 months ago

Agucha1986 commented 4 months ago

Bins argument does not set the required number of ticks. It would be great to have exact number than approximate.

tomroh commented 4 months ago

@Agucha1986, can you provide a reproducible example and the expected output?

Agucha1986 commented 4 months ago

@tomroh, ideally, I would like to get a scale with the minimum and maximum values. I could do that with your example this morning by changing it to a horizontal position. However, this is not possible when its vertical. Simply changing the bins value sometimes does nothing and sometimes increases breaks from 3 to 7 or more. This happens when just changing the bins value from 4 to 5.

So, the below one works and uses the min and max values to display on the legend, and the bins is ignored from what I understand. Is there a way to have a better control over breaks, like in ggplot2?

pal <- colorNumeric("YlGnBu", na.color = "transparent", reverse = T, values(p)) m <- leaflet(data = df,options = leafletOptions(zoomControl = FALSE,attributionControl=FALSE)) %>% setView(lng = lng, lat = lat, zoom = zoom) %>% addProviderTiles(providers$Esri.WorldImagery) %>% addRasterImage(p, colors = pal, opacity = 0.8,project=F) %>% addLegendNumeric(pal = pal, values = values(p), title = htmltools::HTML("label"), position = "bottomright", labelStyle = 'font-size: 14px; font-weight: bold; font-color: black;font-family:Times New Roman', bins = 4, fillOpacity = 0.8, numberFormat = function(x) { prettyNum(x, digits = 3, scientific = F,trim = F, nsmall = 1)}, naLabel = "",orientation = 'horizontal', width = 120, height = 20)

tomroh commented 4 months ago

The bins arg follows leaflet in that the pretty function determines the breaks. The documentation states that the bins argument is an approximate number of breaks.

I added support for manual breaks if you specify a vector > 1 and you can use expressions to set the bins argument.

library(leaflet)
data("quakes")
numPal <- colorNumeric('viridis', quakes$mag)
leaflet(quakes) %>%
  addTiles() %>%
  addLegendNumeric(
    pal = numPal,
    values = ~mag,
    bins = ~range(mag),
    position = 'topright',
    orientation = 'vertical',
    title = htmltools::div('Min/Max w/ Formula', style ='margin-bottom:10px'),
    numberFormat = function(x) sprintf('%.2f', x),
    shape = 'rect',
    decreasing = FALSE,
    height = 100,
    width = 20
  )

You can install from the dev branch and use it right now.

Agucha1986 commented 4 months ago

Thank you very much for clarification.

Best regards,

Aga

On Fri, May 3, 2024 at 3:44 AM Thomas Roh @.***> wrote:

The bins arg follows leaflet in that the pretty function determines the breaks. The documentation states that the bins argument is an approximate number of breaks.

I added support for manual breaks if you specify a vector > 1 and you can use expressions to set the bins argument.

library(leaflet) data("quakes")numPal <- colorNumeric('viridis', quakes$mag) leaflet(quakes) %>% addTiles() %>% addLegendNumeric( pal = numPal, values = ~mag, bins = ~range(mag), position = 'topright', orientation = 'vertical', title = htmltools::div('Min/Max w/ Formula', style ='margin-bottom:10px'), numberFormat = function(x) sprintf('%.2f', x), shape = 'rect', decreasing = FALSE, height = 100, width = 20 )

You can install from the dev branch and use it right now.

— Reply to this email directly, view it on GitHub https://github.com/tomroh/leaflegend/issues/82#issuecomment-2091153821, or unsubscribe https://github.com/notifications/unsubscribe-auth/BH4CXTYXV7DNHUQ43RX2BZDZAJ3PZAVCNFSM6AAAAABG7UGZXCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOJRGE2TGOBSGE . You are receiving this because you were mentioned.Message ID: @.***>

tomroh commented 4 months ago

642cee09047017f9aaab8243e9f9f0725f862c96

Agucha1986 commented 4 months ago

Hi Thomas,

Can I please ask one more question? I have temperature measurements for one day, measured every 10 minutes, which creates a dataset with 144 rows. I need to produce 144 maps, each showing 10-minute data. Later, all these maps will be joined to create an animation to visualise how it changed throughout the day. For this to work, the legend will always need to have the same scale on all maps, ideally the absolute minimum and maximum for that day.

I am planning to use loop, and I was wondering whether you think it is possible to make the same legend for all maps regardless of the min/max values for a particular 10-minute measurement. Thank you in advance. Regards,

Aga

On Sat, May 4, 2024 at 6:36 AM Thomas Roh @.***> wrote:

Closed #82 https://github.com/tomroh/leaflegend/issues/82 as completed.

— Reply to this email directly, view it on GitHub https://github.com/tomroh/leaflegend/issues/82#event-12700915127, or unsubscribe https://github.com/notifications/unsubscribe-auth/BH4CXT3KMKNYIMVNRZSVKUDZAPYOJAVCNFSM6AAAAABG7UGZXCVHI2DSMVQWIX3LMV45UABCJFZXG5LFIV3GK3TUJZXXI2LGNFRWC5DJN5XDWMJSG4YDAOJRGUYTENY . You are receiving this because you were mentioned.Message ID: @.***>

Agucha1986 commented 4 months ago

Further to my email 30 minutes ago, I can't download from @.***') I also tried with remotes and the HTTP link to see if it works,

cannot open URL 'https://api.github.com/repos/tomroh/leaflegend/tarball/devel'

No success.

Aga

On Wed, May 8, 2024 at 6:03 PM Agnieszka Wujeska-Klause < @.***> wrote:

Hi Thomas,

Can I please ask one more question? I have temperature measurements for one day, measured every 10 minutes, which creates a dataset with 144 rows. I need to produce 144 maps, each showing 10-minute data. Later, all these maps will be joined to create an animation to visualise how it changed throughout the day. For this to work, the legend will always need to have the same scale on all maps, ideally the absolute minimum and maximum for that day.

I am planning to use loop, and I was wondering whether you think it is possible to make the same legend for all maps regardless of the min/max values for a particular 10-minute measurement. Thank you in advance. Regards,

Aga

On Sat, May 4, 2024 at 6:36 AM Thomas Roh @.***> wrote:

Closed #82 https://github.com/tomroh/leaflegend/issues/82 as completed.

— Reply to this email directly, view it on GitHub https://github.com/tomroh/leaflegend/issues/82#event-12700915127, or unsubscribe https://github.com/notifications/unsubscribe-auth/BH4CXT3KMKNYIMVNRZSVKUDZAPYOJAVCNFSM6AAAAABG7UGZXCVHI2DSMVQWIX3LMV45UABCJFZXG5LFIV3GK3TUJZXXI2LGNFRWC5DJN5XDWMJSG4YDAOJRGUYTENY . You are receiving this because you were mentioned.Message ID: @.***>

tomroh commented 4 months ago

@.***')

Use main now, it has been merged:

devtools::install_github('tomroh/leaflegend')
tomroh commented 4 months ago

Hi Thomas, Can I please ask one more question? I have temperature measurements for one day, measured every 10 minutes, which creates a dataset with 144 rows. I need to produce 144 maps, each showing 10-minute data. Later, all these maps will be joined to create an animation to visualise how it changed throughout the day. For this to work, the legend will always need to have the same scale on all maps, ideally the absolute minimum and maximum for that day. I am planning to use loop, and I was wondering whether you think it is possible to make the same legend for all maps regardless of the min/max values for a particular 10-minute measurement. Thank you in advance. Regards, Aga On Sat, May 4, 2024 at 6:36 AM Thomas Roh @.> wrote: Closed #82 <#82> as completed. — Reply to this email directly, view it on GitHub <#82 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/BH4CXT3KMKNYIMVNRZSVKUDZAPYOJAVCNFSM6AAAAABG7UGZXCVHI2DSMVQWIX3LMV45UABCJFZXG5LFIV3GK3TUJZXXI2LGNFRWC5DJN5XDWMJSG4YDAOJRGUYTENY . You are receiving this because you were mentioned.Message ID: @.>

Github issues are for bugs/enhancements of the leaflegend package. If you are seeking help with how to code something, you can use StackOverflow or contact me directly.