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

How to extract bar labels and their size from a given ggplot object?

This is a follow-up to a question (and answer) about dynamic word wrapping of x axis labels. EDIT - TL;DR Summary (A) Summary I have a ggplot object made with geom_bar() and ggfittext::geom_bar_text(). I want to extract bar labels from that…
Emman
  • 3,695
  • 2
  • 20
  • 44
1
vote
1 answer

How to create a list of ggplot objects that grid.arrange will accept and draw in r

Update The below code runs now after kernel restart. I'm leaving the question since I didn't see this exact method of converting the plot object into a list and appending. I want to dynamically create a list of ggplot2::ggplot objects (gg) and pass…
Kaleb Coberly
  • 420
  • 1
  • 4
  • 19
1
vote
0 answers

How do I represent an enormous bar plot with very long axis labels in R and ggplot?

I have a ggplot of bar graphs for each cluster. The axis labels ("Path") for the bar plot are all unique and long, but they are grouped by "PathTypes" and "Cluster" - info which I want to represent on the bar graphs. I use a texture (stripes, dots,…
potato
  • 103
  • 7
1
vote
1 answer

Top-align two objects with gridExtra

Say you have two tableGrobs of different sizes, and you want the smaller grob to be top aligned. How might you proceed? Here is an example: library(gridExtra) t1 <- cars[1:9,] t2 <- cars[10:14,] grid.arrange(tableGrob(t1), tableGrob(t2), ncol =…
Kene David Nwosu
  • 828
  • 6
  • 12
1
vote
0 answers

R Multiple rounded corners rectangles in ggplot2 panel layer

I'm trying to create treemaps with rounded corners, like this one 1. I'm using the treemapify package. I've tried using Claus Wilke solution for changing the background rectangle with a rounded rectangle found here: Rounded corners in ggplot2? tm…
1
vote
1 answer

Adjust margins of grob object in r

I made a grob object using the cowplot package. I'm adding grid.lines() and grid.text() objects to finished grob but as it comes out of cowplot it fills the whole page. How can I adjust the margins of the grob object to add some white space around…
CCurtis
  • 1,770
  • 3
  • 15
  • 25
1
vote
1 answer

Resize and move manual grob legend ggplot

I have a ggplot2 object that I'm trying to add a legend for some vlines. I followed the following:(ggplot2: manually add a legend) but I was unable to get my desired output. Any suggestions are much appreciated. Where I got to: My desired output is…
Cyrus Mohammadian
  • 4,982
  • 6
  • 33
  • 62
1
vote
1 answer

R: Is it possible to extract the original data from a gtable object created with grid.arrange and ggplot?

Problem description I have created an gtable (also gTree grob gDesc) object myobj via myobj <- gridExtra::grid.arrange(g1,g2) from two ggplot objects g1,g2 some time ago and now I have to restore the data that I have used to create both ggplots. Is…
R大卫
  • 150
  • 7
1
vote
1 answer

How to add comma separator in triple venn diagram?

I am a beginner in R and I have a functioning code that looks like this library(VennDiagram) grid.newpage() draw.triple.venn(area1=49644, area2=38697, area3=33281, n12=14221, n23=11026, n13=13635, n123=4242, category=c("DOGS",…
astulaaa
  • 11
  • 1
1
vote
1 answer

How to control facet height and width in plotnine?

I have seen this post regarding ggplot2: How to automatically adjust the width of each facet for facet_wrap? I was wondering: how can I achieve the same in plotnine? I haven't found anything similar to grob. I would need it for a plot that is part…
schmat_90
  • 572
  • 3
  • 22
1
vote
1 answer

How to column bind the legend to a computed column in ggplot2?

The code plots data with computed weekly regression lines. I would like to combine the legend with weekly doubling times, computed from the weekly slopes. Nice to solve question: I could get the weekly regression lines with a geom_smooth. However,…
donman
  • 57
  • 3
1
vote
1 answer

R grid package: How to create a textGrob with multiple colors and position it in the center of a viewport

I need something like the following, but with a different color for each word in the String: library(grid) grid.newpage() pushViewport(viewport(width = unit(5, 'cm'), height = unit(5, 'cm'))) grid.rect() grid.text(label = 'Hello, World!') I tried…
Florian
  • 147
  • 3
  • 7
1
vote
1 answer

How to clip a grob into a grobTree object

In R grid graphics how can I clip a grob object in a grobTree ? In a way so I would only need to call grid.draw to plot the clipped grob. For instance when I plot my stuff directly: # Direct plotting ---- library(grid) grid.newpage() vp <-…
1
vote
1 answer

Remove white space of textGrob from grid.arrange

I'm new to grobbing and I am trying to create a simple grid.arrange object but cannot figure out how to might a compact/tight layout. Below is a simple example of what I'm trying to run and the grob that I get. library(grid) library(gridExtra) name…
1
vote
0 answers

Draw table as grob in R

I am trying to implement functionality of gridExtra package in R to display tables as graphics objects. The examples from tutorial Displaying tables as grid graphics/Aesthetic formatting work fine, but when I do my own graphics like below it gives…
Alexander Borochkin
  • 4,249
  • 7
  • 38
  • 53