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
Copy file name to clipboardExpand all lines: vignettes/extending-ggplot2.Rmd
+7-9Lines changed: 7 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -364,11 +364,11 @@ This is very similar to defining a new stat. You always need to provide fields/m
364
364
*`draw_key` provides the function used to draw the key in the legend.
365
365
You can see a list of all the build in key functions in `?draw_key`
366
366
367
-
*`draw_group()` is where the magic happens. This function takes three
367
+
*`draw_panel()` is where the magic happens. This function takes three
368
368
arguments and returns a grid grob. It is called once for each panel.
369
369
It's the most complicated part and is described in more detail below.
370
370
371
-
`draw_group()` has three arguments:
371
+
`draw_panel()` has three arguments:
372
372
373
373
*`data`: a data frame with one column for each aesthetic.
374
374
@@ -381,7 +381,7 @@ Generally you won't use `panel_scales` and `coord` directly, but you will always
381
381
382
382
### Collective geoms
383
383
384
-
Overriding `draw_panel()` is most appropriate if there is one graphic element per row. In other cases, you want graphic element per group. For example, take polygons: each row gives one vertex of a polygon. In this case, you should instead override `draw_group()`:
384
+
Overriding `draw_panel()` is most appropriate if there is one graphic element per row. In other cases, you want graphic element per group. For example, take polygons: each row gives one vertex of a polygon. In this case, you should instead override `draw_group()`.
385
385
386
386
The following code makes a simplified version of `GeomPolygon`:
* We override `draw_group()` instead of `draw_layer()` because we want
437
-
one polygon per group, not one polygon per row. If you look at the source
438
-
code for the original `GeomPolygon` you'll see it actually overrides
439
-
`geom_layer()` because it uses some tricks to make `polygonGrob()` produce
440
-
multiple polygons in one call. This is considerably more complicated, but
441
-
gives better performance.
436
+
* We override `draw_group()` instead of `draw_panel()` because we want
437
+
one polygon per group, not one polygon per row.
442
438
443
439
* If the data contains two or fewer points, there's no point trying to draw
444
440
a polygon, so we return a `nullGrob()`. This is the graphical equivalent
@@ -450,6 +446,8 @@ There are a few things to note here:
450
446
change it there). `lwd` is measured in points, but ggplot2 uses mm,
451
447
so we need to multiply it by the adjustment factor `.pt`.
452
448
449
+
You might want to compare this to the real `GeomPolygon`. You'll see it overrides `draw_panel()` because it uses some tricks to make `polygonGrob()` produce multiple polygons in one call. This is considerably more complicated, but gives better performance.
450
+
453
451
### Inheriting from an existing Geom
454
452
455
453
Sometimes you just want to make a small modification to an existing geom. In this case, rather than inheriting from `Geom` you can inherit from an existing subclass. For example, we might want to change the defaults for `GeomPolygon` to work better with `StatChull`:
0 commit comments