4.13 Venndir Graphics Objects

The Venndir object also stores the grid graphical objects (grobs) used for visualization, however the grobs are only created by calling plot() or render_venndir(). The output of this function is Venndir object with hidden attributes which contain grobs.

When calling venndir(), two options may be useful:

  1. do_plot=TRUE: This argument causes venndir() to call render_venndir(), which then creates the relevant grobs.
  2. do_draw=FALSE: This argument is passed to render_venndir(), so the grobs are not drawn to the graphical device.

The following example creates a Venndir object without creating a new plot, and which creates all the necessary grobs.

v <- venndir(make_venn_test(),
   poly_alpha=0.01,
   border="black",
   border.lwd=2,
   show_labels="Ni",
   main="Plot Title",
   do_plot=TRUE,
   do_draw=FALSE,
   legend_color_style=c("black", "blackborder"))

The relevant attribute names are described as follows:

  • 'gtree': the single grid object that contains all Venndir grobs.
  • 'grob_list': the list of each grid object, separated by type.
  • 'viewport': the grid object representing the graphics viewport.
  • 'adjx', adjy': the adjustment function used to convert JamPolygon coordinates to unit 'nspc' scaled values between 0 and 1.

4.13.1 Venndir gtree

The 'gtree' attribute contains a grid:gTree object, which can be drawn directly. The gtree object already contains the relevant viewport.

Figure 4.25 shows the plot after drawing the 'gtree' attribute.

gtree <- attr(v, "gtree");
grid::grid.newpage();
grid::grid.draw(gtree);
Venn diagram created by drawing the 'gtree' attribute object.

Figure 4.25: Venn diagram created by drawing the 'gtree' attribute object.

A detailed list of all grobs within the gtree can be seen by calling grid::grid.ls(), however it is not listed here because it contains over 350 grobs!

4.13.2 Venndir grob_list

An alternative representation is the 'grob_list' attribute, which is a list with each Venndir visual component. The exact elements may vary dependent upon which options were used.

The purpose of inspecting grid grobs is mainly to allow direct manipulation of the grobs, for advanced customizations for example. Each individual component can be edited in detail.

The grobs by type are described below:

  • 'jps': the JamPolygon object with polygons and border.
  • 'item_labels': item labels, only if enabled by argument show_labels.
  • 'labels': the marquee grobs used for all text labels.
  • 'segments': the line segments connecting labels to polygons, where relevant.
  • 'legend': the grid object representing the Venndir legend, if relevant.
  • 'main_title': the title object, only if defined by argument main.

Figure 4.26 shows the plot after drawing each grid component from the 'grob_list' attribute.

grob_list <- attr(v, "grob_list");

grid::grid.newpage()
grid::grid.draw(grob_list$jps)
grid::grid.draw(grob_list$item_labels)
grid::grid.draw(grob_list$labels)
grid::grid.draw(grob_list$segments)
grid::grid.draw(grob_list$legend)
grid::grid.draw(grob_list$main_title)
Venn diagram created by drawing each component in the 'grob_list' attribute.

Figure 4.26: Venn diagram created by drawing each component in the 'grob_list' attribute.