Slide 1: Title slide. Slide 2: Let us suspend disbelief for a moment and suppose that this is actually a plot someone would want to create. Slide 3: "This" being a 'ggplot2' plot with a radial gradient fill drawn on top. Slide 4: 'grid' can draw radial gradients (from R 4.1.0) NOTE the rgb(0,0,0,0) instead of "transparent" because "transparent" in R is transparent *white* ! Slide 5: 'ggplot2' is built on top of 'grid' Slide 6: 'ggplot2' provides a higher-level interface with its own concepts of geoms and aesthetics etc. 'ggplot2' does not expose 'grid' concepts like viewports and units. Slide 7: 'ggplot2' does not (yet) provide a higher-level interface to radial gradients. And every time something new is added to 'grid' you have to wait for someone to add a 'ggplot2' interface to give you access. Slide 8: It *is* possible to combine 'grid' with 'ggplot2', but there are some drawbacks: grid.force() is a bit mysterious. "panel.7-5-7-5" is a bit mysterious. You need to know quite a bit about both 'ggplot2' and 'grid' to do this. This is not easy to teach! AND you are just drawing on top of everything. Slide 9: AND you DO NOT have access to the coordinate system on the 'ggplot2' axes. So this is at best a mixture of good news and bad news. Slide 10: Isn't that a whole lot nicer ? You just add a 'grid' grob to your 'ggplot2' plot. Slide 11: The only thing to learn is the idea of a "grob". That is a lot easier to teach. Slide 12: You can even add the 'grid' grob ahead of other 'ggplot2' layers if you like. Slide 13: The argument to grid_panel() can be a function. Slide 14: The panel function gets called with the data for each panel. This effectively gives us access to the plot scales. We can see the raw data for the panel. Slide 15: And we can see the transformed data for the panel. Slide 16: The function gets called for each panel so we can draw 'grid' output in different panels. We can use the data for each panel to draw something DIFFERENT on each panel. Slide 17: Output from previous slide. Slide 18: There is also a grid_group() function. That function gets called with the data for each group. The argument to grid_group() can be a grob (draw the same thing for each group) or a function, so we can draw 'grid' output for different groups. Slide 19: Output from previous slide. Slide 20: Summary slide. Slide 21: A set of examples of 'gggrid' in use. Slide 22: The interesting thing here is the use of aes(fill=geo) and scale_fill_manual() that make use of the 'ggplot2' infrastructure to select and map colours to data values, then drawing 'grid' shapes with those colours (to create a background for each panel). It also demonstrates the usefulness of accessing raw 'grid' - there is a ggplot2::geom_rect(), but to get it to fill the plot region you have to use the awkward 'xmin = -Inf'. A rectGrob() has access to 'grid' coordinates like "npc", where "left" is just 0 and "right" is just 1. Slide 23: The interesting bit here is using the aesthetics from the 'ggplot2' mappings to control the colour and size (and x/y location) of the custom data symbols. The usefulness of 'gggrid' here is that we can draw a data symbol that 'ggplot2' does not already have. This comes from the "coolbutuseless" blog. Try not to read too much into the name ... Slide 24: Turns out, at least one person does want to draw a radial gradient on top of a 'ggplot2' plot!!! The usefulness of 'gggrid' here is that 'ggplot2' does not provide an interface to radial gradients, so we need access to raw 'grid'. Slide 25: Acknowledgements for Gallery examples. Slide 26: Links to tech report and software.