You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
report a bug of geom_sf: the legend does not appear, even if show.legend is TRUE #3636
According to the documentation, the legend of geom_sf should be always showed if show.legend is TRUE.
However, if there is no aesthetics other than geometry, the legend of geom_sf does not appear even if show.legend is TRUE.
Below is an example:
What do you envision the legend should show in this example? The only two aesthetic mappings in your plot are position aesthetics, and they have guides along the axes.
Thanks for your reply, and sorry for this late reply.
I think that I may not ask a right question.
I have noticed the lack of any scale for geometry mapping.
Dose it make sense that create a scale for geometry, like "scale_geometry_identity"?
I know it is useless to draw the main plot, but it would be helpful to draw the legend of geom_sf layer, especially when there are multiple layers in the plot (map). @clauswilke
So, are you saying you want to show the type of geometry (point, line, polygon) on the legend? If so, I understand the need to some extent, but we'll never have scale_geometry_*() because geometry is not an aesthetic you can map to some scale. Polygon is polygon.
Besides, IIUC, the legend is not implemented to show the differences of the type of Geom among layers. For example, I guess this is not what you want:
thanks!
I know that one PR cannot solve the problem, so i am preparing multiple PRs.
By now, I think I can solve the problem, but I need to improve the codes before submitting the PRs.
Running #3636 (comment) reprex without the show.legend seems to run as expected on current main branch. Can this issue be closed? If not, would anyone mind explaining what still isn't correct about the behaviour?
Activity
clauswilke commentedon Nov 22, 2019
What do you envision the legend should show in this example? The only two aesthetic mappings in your plot are position aesthetics, and they have guides along the axes.
microly commentedon Nov 25, 2019
Thanks for your reply, and sorry for this late reply.
I think that I may not ask a right question.
I have noticed the lack of any scale for geometry mapping.
Dose it make sense that create a scale for geometry, like "scale_geometry_identity"?
I know it is useless to draw the main plot, but it would be helpful to draw the legend of geom_sf layer, especially when there are multiple layers in the plot (map).
@clauswilke
yutannihilation commentedon Nov 26, 2019
So, are you saying you want to show the type of
geometry(point,line,polygon) on the legend? If so, I understand the need to some extent, but we'll never havescale_geometry_*()becausegeometryis not an aesthetic you can map to some scale. Polygon is polygon.Besides, IIUC, the legend is not implemented to show the differences of the type of
Geomamong layers. For example, I guess this is not what you want:Created on 2019-11-26 by the reprex package (v0.3.0)
yutannihilation commentedon Nov 26, 2019
Btw, I'm a bit skeptical about this part.
If you want to identify each layer, probably you'll need to map the IDs of the layers to some aesthetic (e.g.
colour) anyway.microly commentedon Nov 26, 2019
thanks for your kind reply! @yutannihilation
I understand all you said.
The ggplot2 is a very powerful tool, but it is not as convenient as GIS softwares in drawing maps by geom_sf, especailly in the part of lenged.
As a user of both ggplot2 and GIS, I try to make up the gaps between them by preparing some PRs.
The first one can enable geom_sf automatically determine the legend type, such as point, line and polygon.
I will submit it soon, please consider it.
yutannihilation commentedon Nov 26, 2019
Yeah, I think we all agree with you here (c.f. #3572 (comment)), so PR for this is welcome. But, I'm afraid it won't solve your problem...
microly commentedon Nov 26, 2019
thanks!
I know that one PR cannot solve the problem, so i am preparing multiple PRs.
By now, I think I can solve the problem, but I need to improve the codes before submitting the PRs.
teunbrand commentedon Dec 14, 2023
Running #3636 (comment) reprex without the
show.legendseems to run as expected on current main branch. Can this issue be closed? If not, would anyone mind explaining what still isn't correct about the behaviour?Created on 2023-12-14 with reprex v2.0.2
yutannihilation commentedon Dec 14, 2023
Thanks for the reprex, I agree we can close this issue now.