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

Flags spilling over plot area #4

Open
jimjam-slam opened this issue Sep 16, 2017 · 1 comment
Open

Flags spilling over plot area #4

jimjam-slam opened this issue Sep 16, 2017 · 1 comment
Labels

Comments

@jimjam-slam
Copy link
Owner

jimjam-slam commented Sep 16, 2017

The flag grobs aren't bounded by the plotting area the way other geom grobs (like pointsGrob) are. This appears in the Rstudio rendering device, and in all of the ggplot2::ggsave devices I tested (PDF and PNG). However, it doesn't appear when I save to SVG using gridSVG::grid.export: in that case, the flags are properly bounded by the plotting area.

This doesn't affect the pointsGrob I'm using as an outline for the flags: even if the flags themselves spill over, the outlines stop at the edge.

This is mostly noticeable because the plotting area is calculated based on the position of geoms, not their size (at least not for geom_flag and geom_point. So if you're using appreciable sizes, it makes sense to expand the plotting domain.

@jimjam-slam
Copy link
Owner Author

Here's a test script that illustrates the problem:

library(dplyr)
library(ggplot2)
library(svglite)
library(gridSVG)

devtools::install_github('rensa/ggflags@feature-outlines')
library(ggflags)

# test data
dftest = data_frame(x = 1:4, y = c(2, 1, 2, 1), s = c(4, 2, 2, 4), place = c('au', 'us', 'fr', 'de'))

# construct test plot
testplot =
  ggplot(dftest) +
  geom_flag(aes(x = x, y = y, size = s, country = place)) +
  scale_country() +
  scale_size(range = c(15, 30), guide = FALSE)

# aligned properly but don't clip to the plot area correctly
# (fixable with ggplot2::extend)
ggsave('testplot_ggsave.pdf', testplot)
ggsave('testplot_ggsave.png', testplot)
ggsave('testplot_ggsave_cairo.pdf', testplot, device = cairo_pdf)
ggsave('testplot_ggsave.svg')

# clips to plot area ocrrectly but viewport is off
# (fixable by adjusting viewport attribute of root svg node:
# change viewBox="0 0 526.5 474"to viewBox="0 -158 702 632")
grid.export('testplot_gridsvg.svg')

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

No branches or pull requests

1 participant