Hi everyone, I'm working on some features for my ggflags fork (although I don't know whether @baptiste is interested in a PR, because I haven't asked them yet!) , and I was hoping to canvas some help on a few issues I'm having.
Problem #1: size scaling
My understanding is that scale_size
scales area, not radius. That makes sense when I inspect the size values being passed to my makeContent
function: if I provide scale_size(range = c(0, 20))
to a plot, my points come out like:
Size df column Size given to geom
1 0.0
1.25 10.0
1.5 14.14
1.75 17.32
2 20
But my makeContent
methods draws the geom using width = x$size[ii] * unit(1, "mm")
and height = x$size[ii] * unit(1, "mm")
. I'm guessing this means that I'm essentially scaling twice, which is obviously not what I want. Should I just sqrt()
these figures?
Problem #2: flag strokes not scaling with flags properly
I've added strokes to the flags by essentially plotting a point geom with shape 21 over the top:
grobTree(
grImport2::pictureGrob(
picture = .flaglist[[x$country[[ii]]]],
x = x$x[ii], y = x$y[ii],
width = x$size[ii] * unit(1, "mm"),
height = x$size[ii] * unit(1, "mm"),
distort = FALSE),
pointsGrob(
x = x$x[ii], y = x$y[ii], pch = 21,
gp = gpar(
fill = 0, col = x$colour[ii],
fontsize =
(x$size[ii] * .pt) + (x$stroke[ii] * .stroke),
lwd = x$stroke[ii] * .stroke / 2)))
The strokes aren't out by a fixed amount: at some flag sizes they're too big, and at large font sizes they're too small. I'm kind of guessing this by going on how geom_point
is plotted, but I don't really understand it well enough to get it right. I feel it would be more intuitive for fontsize
to use the same calculation as the flag width and height and then convert to fontsize
units using convertUnits
. Are those units points?
Problem #3: flags (but not outlines) spilling over plotting area
In most cases, the flags keep rendering over the plotting edges:
df = data_frame(x = 1:3, y = 1:3, country = c('au', 'de', 'us'))
ggplot(df) + geom_flag(aes(x = x, y = y, country = country), size = 50, stroke = 2)
This also occurs when using ggsave
(with raster or PDF output) or when using base R devices (png
or pdf
, plot, dev.off
), but it doesn't happen when using grid.export
to save to SVG (it correctly clips them to the plotting area then).
If anyone can shed some light on these problems, it'd be greatly appreciated!