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
1
vote
0 answers

Why grobs on a leaflet map are missing in the saved html file but are printed fine in the Rstudio browser?

In RStudio, I have produced a leaflet map using tmap_leaflet function where some polygons are coloured depending on the value of a variable and on top of the polygons some grobs are printed which show the breakdown of the value of the variable into…
Myr
  • 11
  • 3
1
vote
2 answers

creating custom annotations in only one facet of a ggplot

Is there a way to specify that a custom_annotation only applies to one facet of a ggplot? For example, if I run the following code library(tidyverse) library(grid) text_grob=grobTree(textGrob("text",x=0.5, y=0.6, rot=90, …
Ajjit Narayanan
  • 632
  • 2
  • 8
  • 18
1
vote
1 answer

R tablegrob conditional formating for setting colors based on column values

Is there a way to conditional format a column of a tableGrob or gtable object and color (Red, yellow or Green) it based on a conditional format? For instance: library(gridExtra) library(grid) d = head(iris, 20) d grob=tableGrob(d) I wish to change…
KRStam
  • 393
  • 5
  • 18
1
vote
1 answer

Create and combine 2 grid.tables

I have created a grid.table object to display a dataframe in PowerBi, below there is my code: dataset <- data.frame(BDS_ID = c("001","002"), PRIORITY = c("high","medium"), STATUS = c("onair","onair"), …
Lorenzo Benassi
  • 621
  • 1
  • 8
  • 31
1
vote
1 answer

Format color of specific line of a tableGrob

Is there a way to tell tableGrob via themes to change the color and format (make bold) of a specific line? I get the following output using tableGrob: I however would like to reach the following aesthetic and make specific lines bold and change…
KRStam
  • 393
  • 5
  • 18
1
vote
2 answers

Positioning of grobs

I want to plot data for a linear model in a main plot and a plot of the effects (forest plot) as a subplot using arrangeGrob. Here are the data: set.seed(1) main.df <-…
user1701545
  • 5,706
  • 14
  • 49
  • 80
1
vote
1 answer

R: Drawing a textGrob fails with mysterious error

I have four different kinds of graphic, each converted to a grob with apparent success. I am trying to combine them into a single image with grid.arrange(). One of the four -- I would say the simplest of the four -- produces an error, even without…
andrewH
  • 2,281
  • 2
  • 22
  • 32
1
vote
0 answers

Conditionally Format Coloring of Table in R

Is there a way to conditionally format tableGrob cells/rows when using the gridExtra to export out PDFs? Based on conditional numeric values in a dataframe, I am hoping to change a row color background/fill formatting for my PDF output. Sample Data:…
wetcoaster
  • 367
  • 3
  • 15
1
vote
2 answers

y-axis for each subplot using facet_grid

I can't get the answer to this question to work. What both me and that user want is to add axis ticks and labels to all columns when using facet_grid(). Display y-axis for each subplot when faceting When I run the reproducable example and the…
Nightingale
  • 233
  • 1
  • 10
1
vote
1 answer

"\n" command not working to make 2 or 3-line long figure caption using textGrob

I have been trying to make a 2 to 3-line figure caption below the combined plots using the following script: library(grid) library(gridExtra) library(ggplot2) g1 <- ggplotGrob(pl) #pl is my plot 1 g2 <- ggplotGrob(pl1) #pl1 is my plot 2 g <-…
1
vote
2 answers

ggplot a panel of histograms with histograms as subplots

I have data collected at three sites, where in each these data were collected several times for several subjects. Here's how the data look like: set.seed(1) df <- data.frame(site = c(rep("AA",1000),rep("BB",500),rep("CC",750)), y =…
user1701545
  • 5,706
  • 14
  • 49
  • 80
1
vote
1 answer

Conditional Graph in grid.arrange

Is there a way to use a structure like grid.arrange( ifelse(somecondition,graph1,graph2), ifelse(somecondition2,graph3,graph4), ncol=2 ) where graphX is either a plot (created with ggplot2) or a grob defined previously. It looks like…
Chapo
  • 2,563
  • 3
  • 30
  • 60
1
vote
1 answer

R ggplot2 Remove space between legends dual axis plot

I have two graphs that I'm trying to merge with dual y axes. I'm having trouble getting rid of that space between the two legends that I am trying to merge. Here are my two…
alki
  • 3,334
  • 5
  • 22
  • 45
1
vote
0 answers

Axis Labels that are ggplot2 objects / grobs

I wish to use ggplot2 objects/grobs/plots as axis labels. Here is my toy example: library(dplyr) library(ggplot2) # master plot df <- data_frame(y = c("unchanging", "increasing", "decreasing"), x = c(20, 50, 30)) ggplot(df, aes(x, y)) +…
npjc
  • 4,134
  • 1
  • 22
  • 34
1
vote
2 answers

Using pdf function in R to save plots AND data frames

I recently discovered the function pdf() in R. I know it can only be used to save plots but I wanna use it to save texts and data frames too. So I am trying to cheat the function by using the grid package and grob objects but I cannot figure out how…
jeandut
  • 2,471
  • 4
  • 29
  • 56