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

adjust labels of addLegendSize #60

Closed mtennekes closed 1 year ago

mtennekes commented 1 year ago

I'm working on implementing leaflegend in tmap v4 (https://github.com/r-tmap/tmap/issues/699). One important question:

Can the legend labels be specified in addLegendSize? I'd like to be able to specify any text (e.g. "Very large", "Large", "Medium", "Small") for the symbol sizes.

tomroh commented 1 year ago

Do you mean overwrite 200, 400, 600 with small, medium large?

That's not currently implemented with addLegendSize but is possible with a bit more sweat equity and addLegendImage. I should be able to add that in.

tomroh commented 1 year ago
mtennekes commented 1 year ago

Yes, indeed. That would be great!

From how I understand your (great) package, I will use:

Is addLegendImage the most flexible? Is that correct or do you have suggestions?

Is it possible to generate symbols with makeSymbol and feed that into addLegendImage? If so, I would consider that (because it gives more options. e.g. to vary size, color and shape at the same time.

Btw, can I show a label for missing values in the addLegendNumeric?

mtennekes commented 1 year ago

Just playing with addLegendImage in combination with makeSymbol: awesome! Just what I need. From the source code of makeSymbol I figured out how to change the stroke width: 'stroke-width' = 0.1. Why not just add an argument strokeWidth?

tomroh commented 1 year ago

There are some helper functions too: https://roh.engineering/posts/2021/05/map-symbols-and-size-legends-for-leaflet/

e.g. makeSymbolSize

addLegendImage is the most versatile of those functions, but I think in terms of overwriting text. addLegendFactor can satisfy most of what you need.

Instead of listing all presentation attributes out as arguments, you can use ... to pass them on. strokeWidth is needed for some internal alignment and sizing calculations and I was trying to create a consistent "naming" convention with the "leaflet" package which I wasn't a fan of weight.

tomroh commented 1 year ago

I'm thinking of adding functionality to addLegendSize where you can pass the breaks as a named list e.g. c(small = 10, medium = 20, large = 30). The names would be the label/text.

chrispmad commented 1 year ago

I was looking for exactly this functionality in addLegendSize. Thank you, @tomroh, for this superb package and for adding features like this!

tomroh commented 1 year ago

a75fd0f700991fa39f79e3614ea9e87b8680a250

tomroh commented 1 year ago

Can the legend labels be specified in addLegendSize? I'd like to be able to specify any text (e.g. "Very large", "Large", "Medium", > "Small") for the symbol sizes. Btw, can I show a label for missing values in the addLegendNumeric?

Moving this to #62. The addLegendNumeric is more complex than the other legends and spacing labels becomes an issue for overriding the breaks.

This is complete for other legend functions.