gridextra

How can I add a title to a tableGrob plot?

一曲冷凌霜 提交于 2019-11-30 20:26:11
I have a table, and I want to print a title above it: t1 <- tableGrob(top_10_events_by_casualties, cols=c("EVTYPE", "casualties"), rows=seq(1,10)) grid.draw(t1) A similar question was asked here: Adding text to a grid.table plot I've tried something similar and it doesn't work: > title <- textGrob("Title",gp=gpar(fontsize=50)) > table <- gtable_add_rows(t1, + heights = grobHeight(title) + padding, + pos = 0) Error: is.gtable(x) is not TRUE baptiste Not sure what the problem was, but here is a working example: library(grid) library(gridExtra) library(gtable) t1 <- tableGrob(head(iris)) title <-

ggplot2: multiple plots in a single row with a single legend

吃可爱长大的小学妹 提交于 2019-11-30 19:35:22
I want a combined plot of two plots + their legend like this: library(ggplot2) library(grid) library(gridExtra) dsamp <- diamonds[sample(nrow(diamonds), 1000), ] p1 <- qplot(price, carat, data=dsamp, colour=clarity) p2 <- qplot(price, depth, data=dsamp, colour=clarity) g <- ggplotGrob(p1 + theme(legend.position="bottom"))$grobs legend <- g[[which(sapply(g, function(x) x$name) == "guide-box")]] grid.arrange(arrangeGrob(p1+theme(legend.position="right"),p2+theme(legend.position="none"),legend,ncol=3,widths=c(3/7,3/7,1/7))) However I do not want to guess the width of the plots and legends (and

grid.table and tableGrob in gridExtra package

孤者浪人 提交于 2019-11-30 19:08:30
I am trying to format the table using gridExtra package. The gridExtra package I have is 2.0 and R version is 3.2.1 I was going through answers here on stackoverflow about the formatting and the suggested options seem to work only with older version of the package. For example, grid.table(data, h.even.alpha = 1, h.odd.alpha = 0, v.even.alpha = 1, v.odd.alpha = 1, gpar.corefill, gpar.coretext) All of these options are shown as "unused arguments" in the latest version. Searching further, I found that in new gridExtra package, formatting is defined probably inside theme, example - tt <- ttheme

How to control plot width in gridExtra? [duplicate]

不羁的心 提交于 2019-11-30 14:09:39
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: left align two graph edges (ggplot) I am trying to put two plots produced with ggplot on the same page, top and bottom, so that their widths are the same. The data is from the same time series, x axis being time, so it is important that data points with the same time are not shifted horizontally with respect to each other. I tried grid.arrange from package gridExtra: grid.arrange(p1, p2) but the plots have

gridExtra 2.0.0 change title size

北城以北 提交于 2019-11-30 11:50:08
I know that gridExtra has been updated. As a result, I'm left wondering how to change title sizes. This no longer works grid.arrange(a, b, c, d,ncol=2, nrow=2, main=textGrob("Title", gp=gpar(fontsize=15,font=8))) That no longer works, the option for main has been changed to top but I can't figure out the textGrob features to alter the font size). Any clues? Thanks rolyat First, import the package grid with either library() or require() . Second, change main to top in your code. See below: library(grid) grid.arrange(a, b, c, d,ncol=2, nrow=2, top=textGrob("Title", gp=gpar(fontsize=15,font=8)))

How to control plot width in gridExtra? [duplicate]

狂风中的少年 提交于 2019-11-30 09:26:25
Possible Duplicate: left align two graph edges (ggplot) I am trying to put two plots produced with ggplot on the same page, top and bottom, so that their widths are the same. The data is from the same time series, x axis being time, so it is important that data points with the same time are not shifted horizontally with respect to each other. I tried grid.arrange from package gridExtra: grid.arrange(p1, p2) but the plots have different widths due to different widths of y axis labels. I looked at this post that deals with similar problem, but I could not apply that information to solve my

R: remove repeating row entries in gridExtra table

拜拜、爱过 提交于 2019-11-30 08:41:41
问题 Problem: I create a table using the gridExtra package: require("gridExtra") # Prepare data frame col1 = c(rep("A", 3), rep("B", 2), rep("C", 5)) col2 = c(rep("1", 4), rep("2", 3), rep("3", 3)) col3 = c(1:10) df = data.frame(col1, col2, col3) # Create table grid.arrange(tableGrob(df, show.rownames=F)) The output: Question: I would like to get rid of the repeating row entries and achieve spanning entries which look like this (this image is a mockup made with Photoshop): Any ideas how to achieve

R adding a datatable to a ggplot graph using viewPorts : Scaling the Grob

本小妞迷上赌 提交于 2019-11-30 06:52:01
I'm trying to add a data-table to a graph made in ggplot (similar to the excel functionality but with the flexibility to change the axis its on) I've had a few goes at it and keep hitting a problem with scaling so attempt 1) was library(grid) library(gridExtra) library(ggplot2) xta=data.frame(f=rnorm(37,mean=400,sd=50)) xta$n=0 for(i in 1:37){xta$n[i]<-paste(sample(letters,4),collapse='')} xta$c=0 for(i in 1:37){xta$c[i]<-sample((1:6),1)} rect=data.frame(xmi=seq(0.5,36.5,1),xma=seq(1.5,37.5,1),ymi=0,yma=10) xta=cbind(xta,rect) a = ggplot(data=xta,aes(x=n,y=f,fill=c)) + geom_bar(stat='identity'

grid.arrange ggplot2 plots by columns instead of by row using lists

≯℡__Kan透↙ 提交于 2019-11-30 05:40:37
问题 I want create a multiplot of ggplot2 plots from a list using grid.arrange but arrange them by columns before doing it by rows. gg_list1 <- list(qplot(mpg, disp, data = mtcars), qplot(hp, wt, data = mtcars), qplot(qsec, wt, data = mtcars)) gg_list2 <- list(qplot(mpg, disp, data = mtcars), qplot(hp, wt, data = mtcars), qplot(qsec, wt, data = mtcars)) I know I can do this: do.call(grid.arrange,c(gg_list1,gg_list2 , ncol = 2, nrow = 3)) but it fills from left to right before top to bottom. I've

Arrange many plots using gridExtra

十年热恋 提交于 2019-11-30 04:51:10
问题 I have spent many hours trying to fit 11 graphs in one plot and arrange them using gridExtra but I have failed miserably, so I turn to you hoping you can help. I have 11 classifications of diamonds (call it size1 ) and other 11 classifications ( size2 ) and I want to plot how the median price for each increasing size1 and increasing clarity (from 1 to 6) varies by increasing size2 of the diamonds, and plot all the 11 plots in the same graph. I tried using gridExtra as suggested in other posts