Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bins function does not work properly #82

Closed
Agucha1986 opened this issue Apr 30, 2024 · 9 comments
Closed

Bins function does not work properly #82

Agucha1986 opened this issue Apr 30, 2024 · 9 comments
Assignees
Labels
enhancement New feature or request

Comments

@Agucha1986
Copy link

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

@tomroh tomroh self-assigned this Apr 30, 2024
@tomroh
Copy link
Owner

tomroh commented Apr 30, 2024

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

@Agucha1986
Copy link
Author

@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 tomroh added the enhancement New feature or request label May 1, 2024
@tomroh
Copy link
Owner

tomroh commented May 2, 2024

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
Copy link
Author

Agucha1986 commented May 2, 2024 via email

@tomroh
Copy link
Owner

tomroh commented May 3, 2024

642cee0

@tomroh tomroh closed this as completed May 3, 2024
@Agucha1986
Copy link
Author

Agucha1986 commented May 8, 2024 via email

@Agucha1986
Copy link
Author

Agucha1986 commented May 8, 2024 via email

@tomroh
Copy link
Owner

tomroh commented May 8, 2024

@.***')

Use main now, it has been merged:

devtools::install_github('tomroh/leaflegend')

@tomroh
Copy link
Owner

tomroh commented May 8, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants