-
Notifications
You must be signed in to change notification settings - Fork 121
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
Document tm_legend()
+ add examples
#930
Comments
Good question. I'm open to make things more intuitive. Firstly, these formatting options are part of What do you propose from a users perspective? |
I wonder if all format aarguments could just take a function... World |>
tm_shape() +
tm_polygons(
fill = "HPI",
fill.scale = tm_scale(
label.format = scales::label_percent()
),
popup.format = list(
area = \(x) format(x, digits = 1)
)
)) instead of being list of list. I don't know if it is possible, or if v3 code translations would work with that or not? |
I like this suggestion with direct function specification. This one is working now: World |>
tm_shape() +
tm_polygons(
popup.vars = TRUE,
popup.format = list(
HPI = scales::label_dollar(),
life_exp = \(x) round(x, 1)
)
)
The
Remaining question: what to do with data variables such as |
Thanks! I will test this out! Agreed that the vv should cascade to the popup and legend if possible! The new syntax looks great and is much clearer than nested lists! |
Just committed to make the cascade work in the following way (which hopefully is intuitive and useful): World |>
tm_shape() +
tm_polygons(
fill = "HPI",
fill.scale = tm_scale_intervals(label.format = scales::label_dollar()),
popup.vars = TRUE,
popup.format = list(
inequality = scales::label_percent()
)
) Result: popup labels HPI are in dollars, and inequality in percentages. World |>
tm_shape() +
tm_polygons(
fill = "HPI",
fill.scale = tm_scale_intervals(label.format = scales::label_dollar()),
popup.vars = TRUE,
popup.format = list(
HPI = scales::label_percent()
)
) Result: popup labels HPI are in percentages. In case of conflict like this, the World |>
tm_shape() +
tm_polygons(
fill = "HPI",
fill.scale = tm_scale_intervals(label.format = scales::label_dollar()),
popup.vars = TRUE,
popup.format = scales::label_percent()
) Result: all popup labels are in percentages (at least, all numeric variables), but HPI are in dollars. |
Looks great! thanks |
I am trying to upgrade some code to v4, and I noticed that
tm_legend()
lacks documentation.Furthermore, upgrading the previous code to v4 syntax is the following.
Is there a simpler way to do it?
I didn't get it on the first try as I attempted to do this first, but it didn't work (and didn't warn either)
The text was updated successfully, but these errors were encountered: