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
2 answers

Add grob to a base plot in R

I would like to add a multiline text that I have constructed using splitTextGorb from the package RGraphics to a base plot. I tried the following but this doesn't work (i.e the text doesn't show on the plot) layout(matrix(c(1,2), nrow=2,…
Mayou
  • 8,498
  • 16
  • 59
  • 98
0
votes
0 answers

Changing a grobs plot

I am new here and looking at many answers I have managed to create the following plot that displays the correlation plot of 5 variables, however, I need to modify my code so that it plots the correlations of 7 variables. Can you help me? My code…
0
votes
0 answers

Saving S3 aggr object in a way mice_plots can be visualized by ggplot in a grid arrangement

I am using a for loop to loop through a dataset and produce a mice_plot per category. In the for loop, I would like to save the produced mice_plot so that I can later plot them all in a grid. my code looks like this atm: for center in…
DeMelkbroer
  • 629
  • 1
  • 6
  • 21
0
votes
0 answers

For Loop to move grobs in ggplot using editGrob only working for last element in R

Based on this question: Customize label element position in ggplot using gtable/grob The answer by https://stackoverflow.com/users/5193830/valentin-%c8%98tefan was fantastic and I learnt a lot from it. However I would like to apply editGrob to more…
JoeK
  • 13
  • 3
0
votes
1 answer

Plot grobs on ggplot faceted graph

I have a faceted plot and I want to plot on each facet a different grob (say a table with summary statistics). I tried to use ggpmisc::geom_grob putting the different grobs in a list, but only the last grob is plotted in all of the…
Claudio
  • 1,229
  • 6
  • 11
0
votes
1 answer

How to use a value of a variable as subscripted text in an automated annotation to ggplot

I'd like to add an annotation to my geom_density_ridges() plot which inidicates the defined limit for scale_x_continous() In the example below there is some data to build the plot. The annotation named grob1 leads to the kind of annotation I would…
André
  • 31
  • 6
0
votes
0 answers

R tableGrob cell colors with condition on multiple columns

Is there a way to put colors on all the cells of a tableGrob that are not 0 ? I have this table with a lot of lines [][1] [1]: https://i.stack.imgur.com/w7RCJ.png I am using tableGrob and then grid.arrange to put 2 tables on the same page with some…
0
votes
1 answer

Insert image background while using facet_wrap in R ggplot

I do not get to add a png background to my plot when using the facet_wrap option. Any idea what should work? my data is here library(grid) #complemantory for extra ggplot graphics library(png) #Add a Background Image in ggplot library(tidyverse)…
user12938856
0
votes
1 answer

Properly size multiple ggExtraPlot objects after calling ggMarginal in R

I want to create a facet-like effect with ggExtra::ggMarginal plots. This is not yet directly possible, so I tried to use patchwork::wrap_plots, cowplot::plot_grid, and egg::ggarrange to do it myself. I have everything properly developed—except for…
Prayag Gordy
  • 667
  • 7
  • 18
0
votes
1 answer

rectGrob / textGrob not appearing on plot when using gtable_add_grob

I'm using grid graphics in order to position strip labels on a facet_wrap similar to facet_grid (like this question), and am using the code provided in this answer. I am trying to facet by 2 variables, covariate name and ecoregion. I adjusted the…
mmj1032
  • 3
  • 1
0
votes
1 answer

Change facet_wrap() strip positions to place facet strips inside plot

How can I change the facet_wrap() strip position as it has shown in below picture? The data frames is from this question. enter image description here
0
votes
1 answer

Add a custom element with lines to a ggplot object?

I've made a Kaplan Meier plot using ggplot2 that denotes the disease-free survival (in %) between 3 groups of patients: those unexposed to a risk factor (No exposure), exposed to risk factor 1 (Exposure 1), or those exposed to risk factor 2…
tcvdb1992
  • 413
  • 3
  • 12
0
votes
0 answers

Annotation label won't show when passed as a grob in annotation_custom in r (also trying to put it at the bottom right corner)

I am trying to automatically put a custom annotation in the bottom right corner of a plot no matter the actual axes range. I have tried to do so with annotate from ggplot2 but it just didn't work. I am trying to work with annotation_custom from the…
shoosh_pap
  • 11
  • 2
0
votes
0 answers

How do I set methods inside a package for determining size of a gTree built with grid?

I have written a function to build a plot using grid grobs, and a method to get the width of the resulting gTree. The method function is recognised when run from a script but not when I try to load as part of a package. In my package code file I…
0
votes
1 answer

changing legend of faceted boxplot in ggplot2 to have groups with similar names inside

This question builds off of enter link description here but is in the context of faceted boxplots. So, I have the following code: set.seed(20210714) dd <- data.frame(Method = rep(c("A", "B", "C"), each = 60), Pattern = rep(c("X", "Y", "Z"), times =…
user3236841
  • 1,088
  • 1
  • 15
  • 39