Questions tagged [grob]

stands for **gr**aphical **ob**ject, the generic drawing component in the grid framework of R graphics. Grobs can be very primitive, such as text, rectangles, lines, or complex objects such as full plots built up from many lower-level components.

The recommended grid package is included in every distribution of the R software. As such, it provides a low-level framework for building up all kinds of static graphics. The core component of grid-based graphics is a grob, which in its most basic form is a generic class of objects that describe a graphical component. The most basic grobs are simple shapes such as pointsGrob, polygonGrob, etc., but new objects can be derived from those primitive objects, and are often assembled into a grob tree, or gTree, which holds together multiple shapes together with a specific layout.

Examples of high-level, complex grobs are the complete plots generated by the ggplot2 and lattice packages.

146 questions
7
votes
2 answers

Set the height of the graphs y-axis in grid.arrange, but not of the entire plot area

When using grid arrange I encountered the following problem : I want all my panels (a,b,c) to have the same size, but as I have removed the labels and tickmarks from panel a and b (to have only a single x-axis) the size of the graphs a and b is…
FM Kerckhof
  • 1,270
  • 1
  • 14
  • 31
7
votes
1 answer

Adjusting the "margin" space for axis text in ggplot2

Which property, if any, in ggplot controls the width (or amount of blank space) of the axis text? In the example below, my ultimate goal is to "push in" the left-hand side of the top graph so that it lines up with the bottom graph. I tried…
Ricardo Saporta
  • 54,400
  • 17
  • 144
  • 178
6
votes
1 answer

R: ggplot background gradient coloring

I would like to generate ggplot’s with gradient coloring, filling both plot panel and its background, as herein shown. As you can see the gradient background coloring encompasses both plot panel and its background. At the moment, only an…
GiorgioG
  • 116
  • 6
6
votes
1 answer

Drawing ggplot Footer Using linesGrob within grobTree

I have created an extensive theme to plot in ggplot similar to Five Thirty Eight. Without using ggthemes, how can I utilize linesGrob to draw a line above my footer that is centered and goes 85% of the way across the plot without touching the edges…
medavis6
  • 843
  • 10
  • 32
6
votes
1 answer

Is there a way to save a grob directly to a rasterGrob?

I'm drawing several ggplot2 objects and placing them on a grid.arrange inside a call to a 'pdf' device. I've found that the PDF performs about a billion times better (generates faster, renders faster) if I rasterize the plots first. So inside a…
woodvi
  • 1,898
  • 21
  • 27
5
votes
2 answers

Question on how to draw back-to-back plot using R and ggplot2

I aiming to draw a pyramid plot, like the one attached. I found several example using ggplot, but I am still struggling with the adoption of my example to my data (or the data that I want to plot). structure(list(serial = c(40051004, 16160610,…
Rfanatic
  • 2,224
  • 1
  • 5
  • 21
5
votes
3 answers

Arrange ggplot plots (grobs with same widths) using gtable to create 2x2 layout

I am attempting to use grobs and gtable to arrange 4 (ggplot2) plots into a 2x2 grid. I don't know how to set widths, and also a non- 1xn, or nx1 arrangement. Using this code: data(iris) a <- ggplot(iris, aes(x=Species, y=Petal.Width)) +…
nofunsally
  • 2,051
  • 6
  • 35
  • 53
4
votes
2 answers

How to add a border to a rectangular rasterGrob in ggplot2?

I'm trying to add a border to a rectangular png image (found here) I've added to a ggplot, with positioning specified using npc. library(png) library(grid) library(ggplot2) img <- readPNG("gb.png") g <- rasterGrob(img, x = unit(0.5, "npc"), …
Nautica
  • 2,004
  • 1
  • 12
  • 35
4
votes
2 answers

how to show the title of a table with tableGrob?

Consider this example library(gridExtra) library(grid) d1 <- head(iris[,1:3]) %>% as_tibble() d2 <- head(iris[,2:5]) %>% as_tibble() grid.arrange(tableGrob(d1), tableGrob(d2)) which gives This is really nice but I am missing the…
ℕʘʘḆḽḘ
  • 18,566
  • 34
  • 128
  • 235
4
votes
1 answer

Convert base plot to grob, keeping aspect ratio

I need to convert an R base plot to a grob, so it can be superimposed over some ggplots. There are a couple of functions for doing this that I've found, ggplotify::as.grob and cowplot::plot_to_gtable. The trouble is, they don't preserve the aspect…
Bob
  • 1,274
  • 1
  • 13
  • 26
4
votes
1 answer

Multiple R ggplots on same pdf page

I have an input data frame with 4 columns. test <- head(mtcars[,c(1,2,8,9)]) test mpg cyl vs am Mazda RX4 21.0 6 0 1 Mazda RX4 Wag 21.0 6 0 1 Datsun 710 22.8 4 1 1 Hornet 4 Drive 21.4 6 1 …
user31888
  • 421
  • 6
  • 13
4
votes
1 answer

move ggplot2 contour from other facets to main

I have x,y,z data with categorical variables that facilitate a facet. I want to include contour lines from all but the first facet and discard the rest of the data. One way to visualize the process is to facet the data and mentally move the contours…
r2evans
  • 141,215
  • 6
  • 77
  • 149
4
votes
2 answers

Locate title in top left of grid.arrange

I have two plots arranged side by side with gridExtra::grid.arrange. I can put a title on top of them with the top argument. Problem is, I was requested to locate the title on the top left of the plot. A reproducible…
PavoDive
  • 6,322
  • 2
  • 29
  • 55
4
votes
1 answer

Increase tableGrob column title size and cell size

Is there a way to increase the cell of the column name in a tableGrob item? library(grid) d <- head(iris, 3) g <- tableGrob(d) grid.newpage() grid.draw(g) default: What I want to achieve (this was done in photoshop): Any help is much appreciated.
KRStam
  • 393
  • 5
  • 18
4
votes
1 answer

plotting a list of grobs

DISCLOSURE: I'm not sure how to make a reproducible example for this question. I'm trying to plot a list of grobs using the gridExtra package. I have some code that looks like this: ## Make Graphic Objects for Spec and raw traces for (i in…
Ted Mosby
  • 1,426
  • 1
  • 16
  • 41
1
2
3
9 10