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

inconsistent legend behaviour #8

Closed
joelgombin opened this issue Apr 27, 2015 · 7 comments
Closed

inconsistent legend behaviour #8

joelgombin opened this issue Apr 27, 2015 · 7 comments

Comments

@joelgombin
Copy link
Collaborator

Whether subtitles are used in the legend is not completely consistent.

Compare:

data(World)

rivers$constant <- factor("Rivers")
tm_shape(World) +
    tm_fill() +
tm_shape(rivers) +
    tm_lines(col="constant", palette="dodgerblue3") +
tm_layout_World("World map")

and

rivers$constant <- factor("Rivers")
tm_shape(World) +
    tm_fill() +
tm_shape(rivers) +
    tm_lines(col="constant", palette="dodgerblue3") 

Maybe this is desired, but it can actually become a problem when there is more than one legend item:

data(cities)
cities$constant <- factor("Cities")

tm_shape(World) +
    tm_fill() +
tm_shape(rivers) +
    tm_lines(col="constant", palette="dodgerblue3") +
tm_shape(cities) +
    tm_bubbles(size=1, col = "constant") +
tm_layout("A map")
@mtennekes
Copy link
Member

This was indeed desired, but I'm open to change it if it's counter intuitive.
The background idea is that the main title replaces the title of the first legend element.

In this example, the main title is set to the fill variable, "pop_est_dens":

tm_shape(World) + tm_fill("pop_est_dens") + tm_bubbles("gdp_md_est", col = "economy")

Now, the main title is

tm_shape(World) + tm_fill("pop_est_dens") + tm_bubbles("gdp_md_est", col = "economy") +
tm_layout("Main title")

Now the main title is specified, as well as the legend title for fill:

tm_shape(World) + tm_fill("pop_est_dens") + tm_bubbles("gdp_md_est", col = "economy") +
tm_layout("Main title", legend.titles=c(fill="population density"))

@mtennekes
Copy link
Member

Applied to your example:

tm_shape(World) +
    tm_fill() +
    tm_shape(rivers) +
    tm_lines(col="constant", palette="dodgerblue3") +
    tm_shape(metro) +                           ## I replaced the cities dataset by metro
    tm_bubbles(size=1, col = "constant") +
    tm_layout("A map", legend.titles=c(bubble.col="Cities"))

@mtennekes
Copy link
Member

A problem may arise when multiple legend items will be supported [https://github.com/mtennekes/tmap/issues/2]

The reason for this behavior was that most thematic maps will probably have only one legend element. For that element, it's overkill to have two titles (a main title and a legend title).

A logical improvement could be that a legend title is only overruled by the main title if there is one legend element.

@joelgombin
Copy link
Collaborator Author

OK, I didn't see there a legend.titles argument, my bad!

@mtennekes
Copy link
Member

Still a useful issue!

I'll change it to make it more intuitive: in the next update, there will be a title argument for each aesthetic in each layer, and maybe other legend options as well. Only layout settings that are not legend-item-specific will be processed in tm_layout.

@mtennekes
Copy link
Member

Just started a "legends" branch for this.

@mtennekes
Copy link
Member

Done! Legend titles are now specified inside the layer functions, and the main title in tm_layout.

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

No branches or pull requests

2 participants