Questions tagged [r-grid]
grid is an R package providing low-level plotting facilities.
332
questions
1
vote
0
answers
30
views
Calculate the width of a geom_text in ggplot2 [duplicate]
When adding text labels next to (or above) bars with geom_text, there is no way to automatically leave enough room for the label. Example:
library(ggplot2)
pdata <- data.frame(group = c("A&...
1
vote
1
answer
27
views
par('usr') equivalent command for grid?
When grid package is used to plot a figure, I want to find out something similar to par('usr') as in base R graphics. What command can do it?
https://r-graph-gallery.com/100-high-density-scatterplot-...
2
votes
0
answers
36
views
Edit or undo segment or text for real time plot in R
Say I want to display a web data stream in real time in a plot in R. Is there a way, to just draw and undraw the most recent text box or segment over the existing plot, rather than drawing the entire ...
1
vote
0
answers
27
views
Superscript text_Grob [duplicate]
I have a fiddley little problem! I am trying to get a superscript (i.e. the -1 in "Mg:Ca(µmol mol-1)" into a text grob but can't find the correct annotation of the script:
Axis labels
...
0
votes
0
answers
22
views
Making arrangegrob title and individual plot margins smaller
I am using grid.arrange together with arrangegrob to make one large picture of 30 individual levelplots. I would like to make the margins between the titles of the arrangegrob elements en the elements ...
0
votes
0
answers
37
views
How to produce SVG that would fill the entire screen?
The code below creates a circle using the R grid graphics. I would expect the chart to fill the entire screen instead it fills only a fraction (top-left) of the screen. I am on a Windows computer and ...
0
votes
2
answers
215
views
How to put y axis title in top left corner of graph using grid's functions?
I want to write the y-axis title horizontally on top of the y-axis line while keeping settings defined for the y-axis in the theme() function. The objective is to avoid wasting space while keeping a ...
1
vote
0
answers
37
views
Extract plotting region coordinates for grid.picture() in R
Background
I am plotting the following image:
Using this code:
par(mfrow = c(2, 2),
mar = c(2, 2, 2, 2))
plot(1, col = "red", pch = 15)
plot(1, col = "blue", pch = 15)
plot(1,...
1
vote
1
answer
45
views
Curve between two rectangles is not shown
I am trying to connect the two rectangles with a curved arrow, but no curve is drawn. Could you please help me?
Thanks!
library(grid)
grid.newpage()
pushViewport(plotViewport(c(2, 2, 2, 2)))
xis &...
0
votes
1
answer
62
views
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", &...
1
vote
1
answer
405
views
changing the legends in ggplot2 to have groups of similar labels
this question builds off of this solution provided at enter link description here
as follows.
library(ggplot2)
library(gtable)
library(grid)
diamonds$cut = factor(diamonds$cut, levels=c("Fair&...
2
votes
1
answer
94
views
Convert a wordcloud to a grob / include it in grid.arrange (R)
I have built a more complex output via grid.arrange and now I want to include a wordcloud(2). The ggplot wordcloud function is not an option, since it works much slower for my task. But grid.arrange ...
1
vote
0
answers
51
views
Saving output plot in R with grid.grab() doesn't work
I've been trying to save multiple plot generated with the meta package in R, used to conduct meta-analysis, but I have some troubles. I need to save this plot to arrange them in a multiple plot figure....
3
votes
2
answers
515
views
Margin above title in ggplot created with grid.arrange
I have two ggplots that I can created like this:
df1 = data.frame(x=1:10, y1=11:20, y2=21:30)
gg1 = ggplot(df1) + geom_point(aes(x=x, y=y1))
gg2 = ggplot(df1) + geom_point(aes(x=x, y=y2))
grid.arrange(...
1
vote
1
answer
1k
views
Plot table next to plot and below legend in ggplot2
I have this data frame and table:
circ.plot <- structure(list(ID = c("GO:0010257", "GO:0097031", "GO:0032981",
"GO:0006120", "GO:0046654", "...
1
vote
0
answers
19
views
ragg anti-aliasing for touching polygons
I'm rendering a series of touching polygons with grid and saving this to a png file using the ragg package. Whenever I do this with the ragg package, I get a white grid atop my polygons where they ...
0
votes
0
answers
46
views
hexbin and ggplot in different panels
I'd like to combine a hexbin plot with a ggplot in different panels in R. I can get kinda close, but it's still not working:
library(hexbin)
library(ggplot2)
library(grid)
x1 <- rnorm(100)
y1 <...
0
votes
0
answers
122
views
how to arrange tables in specific place grid.arrange
I am using the gtable and gridExtra packages to manipulate PDF. I am struggling with setting the place manually for my tables i.e I would like to be both of the more in the center not so close to the ...
1
vote
1
answer
198
views
Is there a way to change background color or color the inverse of the input sets?
I'm working on a shiny app to let students explore the basic probability equations and notation with dynamic Euler (Venn) diagrams responding to changes in probability and displaying the intersection ...
1
vote
0
answers
34
views
Choose font for transition diagram in GMisc
How can one change the text font in a transition diagram created with the GMisc package in R?
I can get 2% of the way there as follows:
library(grid)
library(Gmisc)
grid.newpage()
txt <-
"...
1
vote
1
answer
124
views
Is there any way to convert a gTree back to a workable ggplot in r?
Here is some example data:
exampledata <- structure(list(x = c(2.93131952459005, 3.21275054434318, 1.36466997175509,
2.13626543532502, 1.45889556823722, 1.94598707699052, 0.719062322132357,
2....
4
votes
1
answer
282
views
Exact dimensions of linetype spacing and size
This is mostly a follow-up question on a previous one.
Given that in ggplot2 and grid there are different linetypes and spacings vary between line sizes, what is their relationship?
There are two ...
10
votes
2
answers
309
views
How to keep linetype spacing constant despite line size
I've been attempting to plot lines in either ggplot2 or grid with equal spacing between line segments when the sizes differ. However I've not been succesfull so I ask you for help.
In the examples ...
1
vote
1
answer
197
views
Isn't this function for grid.arrange correct?
grid.arrange(hist1, hist2, nrow = 2)
This is the line of code with error
The error shown is -------------------------------------
Error in grid.arrange(hist1, hist2, nrow = 2) :
could not find ...
6
votes
3
answers
3k
views
Combine multiple facet strips across columns in ggplot2 facet_wrap
I am trying to combine facet strips across two adjacent panels (there is always two adjacent ones with the same first ID variable, but with two different scenarios, let's call them "A" and &...
2
votes
1
answer
431
views
How to increase space among different boxes created for the facet labels using `facet_nested`?
I have a plot like this below:
library(ggplot2)
library(ggh4x) # remotes::install_github("teunbrand/ggh4x")
df1 <- data.frame(x = rep(1:12, times=4, each=1),
y = rep((1:12)^2, ...
0
votes
1
answer
308
views
using grid to annotate lattice plots outside of the plotting region
I often use the lattice package to create figures. I then use grid::grid.text() to annotate the figures outside of the plotting region. Typically, I make PDF files, and there are no problems.
I now ...
0
votes
1
answer
57
views
get the most common source-destination trajectories in R
I have two spatial points dataset, one for origins and one for destinations.
I'd like to take the most recurring trajectories from these coordinates.
> salidas
class : ...
0
votes
2
answers
433
views
Draw arbitrary lines in margins, R plot with several panels
I have this code
par(mfrow = c(1,2))
plot(1:5, 5:1)
Which makes this plot
I'd like to be able to add random lines all over the plot (see red lines for example). They could be on the plot themselves,...
0
votes
1
answer
130
views
Data.frame header on every PDF page (R - grid & gridExtra)
I'm trying to print a PDF of a 100-line dataframe on multiple pages. Following the model proposed by baptiste, it is possible to do it using the {grid} and {gridExtra} packages.
However, the result ...
1
vote
1
answer
1k
views
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....
1
vote
1
answer
100
views
Is there a way to converting a function with a series of grid.* and viewport calls to a grob/gTree?
Is there a simple way of taking an arbitrary function with a series of calls to grid.* functions and viewport actions, like the first function below, and getting back a gTree/grob object like the one ...
9
votes
1
answer
14k
views
How To Edit Common Legend Title In ggarrange?
How do I edit a common legend title (make it bold font and enlarge the font size) using ggarrange?
Based on the six plots I have (p1 to p6), I thought the following would work:
p6 <- p6 + theme(...
1
vote
1
answer
132
views
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 ...
3
votes
2
answers
724
views
R convert grid units of layout object to native
My problem is somewhat related to Convert units from npc to native using grid in R .
I'm trying to figure out the location of certain plot elements start in a ggplot2 object (axes, main plot, etc). I ...
2
votes
0
answers
151
views
grid: stretching and rotating a raster
I have a matrix that would like to display as a raster, in a 45 degree rotated fashion and it should stretch along the x- and y- directions to fit the graphics device.
Questions that I've found that ...
1
vote
1
answer
334
views
grid package: Save plot of multiple grobs in one object
I'm assembling several grobs in one image. I can save the output to file in RStudio, but how can I assign it to an object inside R?
Here is an example:
library(ggplot2)
library(grid)
#create the ...
1
vote
1
answer
579
views
Using grid to create and save a small png file
I am using R to create a number of small graphics that will be saved as PNG files, typically at 50x50 pixels, which for eventual use in a much larger image as icons or markers. As the content changes ...
0
votes
3
answers
417
views
How do I create a "for" loop in r that assigns ggplots as an object without saving over them
I'm using the grid and grid.Extra packages to have multiple ggplots on one grid, however, I need to make 28 ggplots in total, each one with a different y variable. Obviously the loop to make and save ...
2
votes
0
answers
415
views
Draw a square with grid in ggplot2
I am trying to create my own geom. On screen, the geom should always be a square, irrespective of scaling. Given the values w and h (for width and height), transformed by ggplot from user coordinates ...
2
votes
1
answer
118
views
ggplot2: return value from draw_panel
I am learning to code in ggplot2. I wish to create a new geom which makes something complex – not a simple polygon. Say, a rectangle with a point in the middle.
When I am defining my new geom object, ...
0
votes
0
answers
480
views
Using grid.edit and grid.remove on grobs saved using ggplotGrob
I have a complicated ggplot2 plot made with an home made function (not from me) that I want to reuse in my own plot function. I want to use the grid package to reorganize everything. I've found this ...
4
votes
1
answer
1k
views
How to plot an aligned text on severals lines / colomns?
I am creating a "page" via several lines and columns with aligned text (left/right/top/bottom). I would like to use the grid.arrange() function but I can't do it. I read in an old post that the ...
5
votes
2
answers
737
views
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). ...
3
votes
0
answers
115
views
I have a list of grobs. How do I make a glist or gtree?
I have a list of Grobs
my_grob_list = list(
grid::pointsGrob(1, 2, 16, gp = grid::gpar(col = "red")),
grid::pointsGrob(3, 4, 16, gp = grid::gpar(col = "blue"))
)
How do I create a gList or gTree ...
1
vote
1
answer
54
views
Connecting Lattice graphs in different grid viewports
Lattice is based on Grid universe. Connecting the panels of lattice graphs placed on different viewports should be easy. But it seems panels crop the line between them.
I want to connect the big ...
1
vote
2
answers
392
views
How to create plot with multiple labels on X axis, previous code suggestion doesn't seem to work
I have some data measuring rate of dislodgement for a species with three different variables (exposure, season and site). I would like to create a plot where Season and exposure are listed on the X ...
0
votes
0
answers
39
views
R mosaic() shade is not coloring the data [duplicate]
I have the following code:
#Loading libraries
library(grid)
library(vcd)
#creating table
ds = array(c(14,4,7, 10,15,9, 3,11,5), dim=c(3,3),
dimnames=list('Radio Format Preference'=c('Music','News-...
0
votes
0
answers
153
views
vertical alignment of gridExtra tableGrob
Solved - be sure to send a list to lapply! Thanks Baptiste, and once again you rock!
Multiple questions have been asked about this, and this seems to be the accepted answer from Baptiste.
When I ...
1
vote
1
answer
944
views
ggplot - Same x-axis length for aligned plots with 2 and 3 y-axis
I wish to align a 3-y-axis plot with a 2-y-axis plot so that x-axis' lengths would be identical.
But, owing to the third axis of the first plot, x-axis' lengths are different among plots.
library(...