ggflags icon indicating copy to clipboard operation
ggflags copied to clipboard

Dynamically add a stroke to the flags

Open jimjam-slam opened this issue 8 years ago • 6 comments

Not sure if this is possible if they're basically equivalent to geom_point... I can theoretically load in an alternate set of SVGs that have strokes hard-coded into them, but when I tried to do it with <circle> elements, convertPicture didn't like them. Plus, it'd be neat to do custom strokes without fiddling about.

I suppose if I'm desperate I could add a separate, slightly larger geom_point behind the flags... can't jitter unless I do it manually then, though :/

jimjam-slam avatar Sep 07 '17 12:09 jimjam-slam

I've gotten this starting to work in rensa/ggflags@caee020. When a stroke aesthetic is supplied, instead of rendering just a pictureGrob, I instead render a gTree that contains the pictureGrob and a pointsGrob of shape 21 (a ring). Because they make up a single geom, this should work with jitters ~~(though I haven't tested it yet)~~ (confirmed).

However, there are some problems:

  • [ ] Outline sizes aren't calculated properly, so they don't stay on the flag edges. I'm basing the sizing on solitary geom_points, but I don't understand it too well. I'm also worried that size may be scaling to radius rather than area, as it should (I'm not sure if the size values given to the geom are scaled to area beforehand).
  • [x] ~~Colours are totally messed up (see below), and it seems like they 'stick' if i draw a new plot with modified data. I'm guessing this is a scope problem: variables getting created and hanging around after the draw instead of being cleared. Not too sure.~~

Example:

> df = data_frame(x = 1:4, y = 4:1, siz = c(1,2,1,2), count = c('au', 'us', 'gb', 'de'), colo = c('black','red', 'green', 'blue'))
> df
# A tibble: 4 x 5
      x     y   siz count  colo
  <int> <int> <dbl> <chr> <chr>
1     1     4     1    au black
2     2     3     2    us   red
3     3     2     1    gb green
4     4     1     2    de  blue
> ggplot(df) +
  geom_flag(aes(x = x, y = y, size = siz, country = count, colour = colo), stroke = 3) +
  scale_size(range = c(5, 10))

ggflags-problems

jimjam-slam avatar Sep 16 '17 13:09 jimjam-slam

Stroke colours render correctly when supplied statically (ie. not as aesthetics). But they're incorrect when supplied as aesthetics (whether as keywords, like "red", or as hexcodes, like "#ff0000").

jimjam-slam avatar Sep 16 '17 14:09 jimjam-slam

Well, I clearly need my sleep: I totally forgot that when you supply an expression to the colour aesthetic, the unique values of that expression aren't actually used as colour arguments (the unique values are just used to group the geoms).

The above example needed:

+ scale_colour_manual(
  values = c(
    'black = 'black',
    'red' = 'red',
    'green' = 'green',
    'blue' = 'blue'))

Yep. Time for bed.

jimjam-slam avatar Sep 16 '17 15:09 jimjam-slam

Was this ever implemented? I can't make it work

fabeit avatar Jun 09 '21 14:06 fabeit

It wasn't, I'm afraid!

jimjam-slam avatar Jun 09 '21 23:06 jimjam-slam

Actually, I believe my progress on this is on the feature-outlines branch. So if you install that branch using devtools, you might have some luck! I don't rememberif I ever finished it, though 😭

jimjam-slam avatar Jun 09 '21 23:06 jimjam-slam