Discover the Art of Creating Glist: A Comprehensive Guide to Using Only 'Grobs' Allowed

Learn how to harness the power of 'grobs' in R's Grid graphics system to create custom and visually appealing Glists. This guide will dive deep into the world of 'grobs' and show you step-by-step how to create and manipulate them to achieve desired graphical outputs.

Table of Contents

  1. Introduction to Grobs
  2. Creating a Glist
  3. Manipulating Grobs
  4. Examples of Glist Usage
  5. FAQ

Introduction to Grobs

'Grobs' or Graphical Objects are the basic building blocks of the Grid graphics system in R. They are low-level graphical elements that can be combined and customized to create complex graphical designs. Some common types of 'grobs' include text, lines, rectangles, and points.

To get started with 'grobs', you'll need to have the grid package installed and loaded in R. If you haven't already, you can install it using the following command:


Then, load the package by running:


For more information on the Grid graphics system and 'grobs', check out the official Grid Graphics documentation.

Creating a Glist

A Glist is a collection of 'grobs' that can be easily manipulated and organized. You can create a Glist using the gList() function from the grid package. Here's a step-by-step guide on how to create a Glist:

  1. Create individual 'grobs' using functions like textGrob(), rectGrob(), linesGrob(), etc.
text_grob <- textGrob("Hello, World!", x = 0.5, y = 0.5, gp = gpar(fontsize = 24))
rect_grob <- rectGrob(x = 0.5, y = 0.5, width = 0.5, height = 0.5)
  1. Combine the 'grobs' into a Glist using the gList() function.
glist <- gList(text_grob, rect_grob)
  1. Display the Glist using the grid.draw() function.

Manipulating Grobs

You can manipulate 'grobs' in various ways, such as changing their position, size, or appearance. Here are some common methods for manipulating 'grobs':

  • Change Position: Use the x and y arguments to set the position of the 'grob'.
text_grob$x <- 0.25
text_grob$y <- 0.75
  • Change Size: Use the width and height arguments to set the size of the 'grob'.
rect_grob$width <- 0.25
rect_grob$height <- 0.25
  • Change Appearance: Use the gp argument to set graphical parameters like color, font size, line type, etc.
text_grob$gp <- gpar(col = "blue", fontsize = 18, fontface = "bold")
rect_grob$gp <- gpar(fill = "lightblue", col = "blue", lty = "dashed")

For a detailed list of graphical parameters, refer to the gpar() documentation.

Examples of Glist Usage

Here are some practical examples showcasing the power and flexibility of Glists:

  1. Creating a custom axis for ggplot2
  2. Adding annotations and labels to plots


What are some common 'grobs' I can use in my Glist?

Here are some commonly used 'grobs' and their corresponding functions:

  • Text: textGrob()
  • Rectangles: rectGrob()
  • Lines: linesGrob()
  • Points: pointsGrob()
  • Circles: circleGrob()
  • Polygons: polygonGrob()

How do I change the order in which 'grobs' are drawn in a Glist?

You can change the order of 'grobs' in a Glist by reordering the elements within the Glist:

glist <- gList(rect_grob, text_grob)

Can I use 'grobs' and Glists with ggplot2?

Yes, you can use 'grobs' and Glists with ggplot2 by using the annotation_custom() function. Check out this example of using Glists with ggplot2.

How do I save a Glist as an image file?

You can save a Glist as an image file (e.g., PNG, JPEG) using the grid.export() function from the grid package:


How can I add interactivity to my Glist?

To add interactivity to your Glist, you can use the gridSVG package, which allows you to create interactive SVG graphics using 'grobs' and Glists. You can find more information and examples in the gridSVG documentation.

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.