grob

plotting a list of grobs

百般思念 提交于 2019-12-06 08:50:45
问题 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 1:length(morletPlots)){ gridplots_Spec[[i]]=ggplotGrob(morletPlots[[i]]) gridplots_Raw[[i]]=ggplotGrob(rawPlot[[i]]) gridplots_Raw[[i]]$widths=gridplots_Spec[[i]]$widths } names(gridplots_Spec)=names(morletPlots) names(gridplots_Raw)=names(rawPlot) ##

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

杀马特。学长 韩版系。学妹 提交于 2019-12-05 11:31:17
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, 16090310), DMSex = structure(c(2, 2, 2), label = "Gender from household grid", labels = c(`No answer/refused` = -9, `Don't know` = -8, `Interview not achieved` = -7, `Schedule not applicable` = -2, `Item not applicable` = -1, Male = 1, Female = 2), class = "haven_labelled"), dtotac = structure(c(-9, -9, -8), label = "DV: Total actual hours in all jobs

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

回眸只為那壹抹淺笑 提交于 2019-12-04 20:22:06
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 <- rbind(g1, g2) #this combines my two plots caption <- textGrob(expression(paste(bold("Figure 1"), ". This is the first line with a", italic( " scientific name."),"\nThis should be the second line.","\nThis is the third line.")), hjust=0, x=0) #caption to be incorporated at the lower left of the combined plots g <- gtable::gtable_add_rows(g, unit(2,"mm") +

plotting a list of grobs

你。 提交于 2019-12-04 13:06:51
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 1:length(morletPlots)){ gridplots_Spec[[i]]=ggplotGrob(morletPlots[[i]]) gridplots_Raw[[i]]=ggplotGrob(rawPlot[[i]]) gridplots_Raw[[i]]$widths=gridplots_Spec[[i]]$widths } names(gridplots_Spec)=names(morletPlots) names(gridplots_Raw)=names(rawPlot) ## Combine spec and Raw traces g=list() for (i in 1:length(rawPlot)){ g[[i]]=arrangeGrob(gridplots_Spec[i]

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

拜拜、爱过 提交于 2019-12-03 07:58:23
问题 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)) + geom_boxplot(color="black") + ylab(expression(Foo~Bar~(g~cm^{-3}))) b <- ggplot(iris, aes(x=Species, y=Petal.Length*100)) + geom_boxplot(color="black") + ylab("foobar (mm)") c <- ggplot(iris, aes(x=Species, y=Sepal.Width)) + geom_boxplot(color="black") + ylab

R tableGrob heatmap or conditional formating in column

我们两清 提交于 2019-12-02 09:19:28
问题 Is there a way to create a similar effect to excel's conditional formating -> color scales in order to present a table in grid.table/tablegrob object? The color indicator should be red for the lower values and green for the higher values in the column. That object format is needed so the table can be presented in grid format along with plots. Thank you. 回答1: You can do this within tableGrob . You create a vector of colours, and then assign these to the cells. So using the data from clemens's

R tableGrob heatmap or conditional formating in column

↘锁芯ラ 提交于 2019-12-02 07:29:18
Is there a way to create a similar effect to excel's conditional formating -> color scales in order to present a table in grid.table/tablegrob object? The color indicator should be red for the lower values and green for the higher values in the column. That object format is needed so the table can be presented in grid format along with plots. Thank you. You can do this within tableGrob . You create a vector of colours, and then assign these to the cells. So using the data from clemens's answer: library(gridExtra) library(grid) # define colour vector # change `vec` argument of `findInterval` to

Universal x axis label and legend at bottom using grid.arrange

我与影子孤独终老i 提交于 2019-12-01 18:52:57
I am trying to plot a number of graphs next to each other using grid.arrange. Specifically, I would like the plots to have a shared x axis label and a legend at the bottom. Here is the code I am using for the arrangement ( working example here ), sans the universal x axis: plot.c <- grid.arrange(arrangeGrob(plot.3 + theme(legend.position="none"), plot.2 + theme(legend.position="none"), plot.4 + theme(legend.position="none"), nrow=1), my.legend, main="Title goes here", left=textGrob("Y Axis", rot = 90, vjust = 1), nrow=2,heights=c(10, 1)) The legend is a TableGrob object; the universal x axis

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

人盡茶涼 提交于 2019-12-01 15:50:10
问题 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 bigger and equals the size of graph c + space for the lable and tick-marks of c. I cannot make use of ggplot2::facet_grid either, since I want to specify the y-axis limits independently (eg. of a until 40 and of b and c until 15). Below you can find

R tableGrob change format of row

£可爱£侵袭症+ 提交于 2019-11-29 23:21:53
问题 I have some relatively simple code to create a table for printing to a PDF: library(gridExtra) df <- head(iris) tableGrob(df, gp = gpar(fontsize = 8), rows = NULL) I'd like to make the last row the same format as the header row (bold, and darker gray background). I understand I can use gpar to control format of the entire table, but not sure how to just affect the last row. Thanks! 回答1: One option is to create a new table, and merge the two together, g1 <- tableGrob(iris[1:4, 1:3], rows=NULL)