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
Saving svg plots using ggsave() makes geom_rect disappear, but not with svg() #5121
When I save plots with geom_rect() using either ggsave() or svglite::svglite() the rectangles disappear, but not when I use grDevices::svg() or png formats.
ggsave(plot=loghistGraph, file="bugGraph.svg")
#> Saving 7 x 5 in image
ggsave(plot=loghistGraph, file="OkayGraph.png")
#> Saving 7 x 5 in image# WorksgrDevices::svg("DefaultSvgWorks.svg")
print(loghistGraph)
dev.off()
#> png #> 2# Doesn't work and save as ggsave
svglite("svgliteBug.svg")
print(loghistGraph)
dev.off()
#> png #> 2
As far as I can tell, {svglite} exports the rectangles as 'rect's, while svg() exports them as 'path's. The rectangles are still there in the text output of {svglite}, but I think they might not get rendered because they have 0-width.
The width and height properties define the overall width and height of the rectangle. A negative value for either property is illegal and must be ignored as a parsing error. A computed value of zero for either dimension disables rendering of the element.
So I think everything is working as it should; it is just a difference in interpretation of what output to the file is (a 'rect' vs 'path'). In any case, I don't think ggplot2 has any control over this implementation.
Giving this another thought, I don't think there is anything to fix here at ggplot2's side, as this relates to how graphics are translated between R and devices. If you do insist on this plot working, either give the rectangles a small width or use a line to represent the data. Despite that this is unlikely to change in ggplot2, I do want to thank you for preparing the examples, and hope to hear from you again when you find new issues.
Activity
teunbrand commentedon Dec 27, 2022
As far as I can tell, {svglite} exports the rectangles as 'rect's, while
svg()exports them as 'path's. The rectangles are still there in the text output of {svglite}, but I think they might not get rendered because they have 0-width.From the SVG docs here:
So I think everything is working as it should; it is just a difference in interpretation of what output to the file is (a 'rect' vs 'path'). In any case, I don't think ggplot2 has any control over this implementation.
Fix tidyverse#5121
teunbrand commentedon Jan 10, 2023
Giving this another thought, I don't think there is anything to fix here at ggplot2's side, as this relates to how graphics are translated between R and devices. If you do insist on this plot working, either give the rectangles a small width or use a line to represent the data. Despite that this is unlikely to change in ggplot2, I do want to thank you for preparing the examples, and hope to hear from you again when you find new issues.