gtable

gtable: Put a black line around all cells in the table body

我是研究僧i 提交于 2020-01-05 10:06:11
问题 I'm trying to put a relatively heavy line (say lwd = 2 size) around the body of a table using gridExtra . Here's a MWE slightly modified from this documentation page. gtable is doing the work under the hood but the documentation for gtable is thin; looking at the code didn't help much. g <- tableGrob(iris[1:4, 1:3], rows = NULL) separators <- replicate(1, segmentsGrob(x1 = unit(0,"npc")), simplify=FALSE) g <- gtable::gtable_add_grob(g, grobs = separators, t = 1, b = nrow(g), l = 1) g <-

Vertically align of plots of different heights using cowplot::plot_grid() when using coord_equal()

天大地大妈咪最大 提交于 2020-01-04 17:34:08
问题 I am trying to combine two ggplot objects using cowplot::plot_grid() and vertically align them. This is normally quite simple using align = "v" . dat1 <- data.frame(x = rep(1:10, 2), y = 1:20) dat2 <- data.frame(x = 1:10, y = 1:10) plot1 <- ggplot(dat1, aes(x = x, y = y)) + geom_point() plot2 <- ggplot(dat2, aes(x = x, y = y)) + geom_point() cowplot::plot_grid(plot1, plot2, ncol = 1, align = "v") However, this approach fails when the ggplots use coord_equal() because plot_grid() cannot modify

Vertically align of plots of different heights using cowplot::plot_grid() when using coord_equal()

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-04 17:32:21
问题 I am trying to combine two ggplot objects using cowplot::plot_grid() and vertically align them. This is normally quite simple using align = "v" . dat1 <- data.frame(x = rep(1:10, 2), y = 1:20) dat2 <- data.frame(x = 1:10, y = 1:10) plot1 <- ggplot(dat1, aes(x = x, y = y)) + geom_point() plot2 <- ggplot(dat2, aes(x = x, y = y)) + geom_point() cowplot::plot_grid(plot1, plot2, ncol = 1, align = "v") However, this approach fails when the ggplots use coord_equal() because plot_grid() cannot modify

Create a ggplot2 survival curve with censored table

笑着哭i 提交于 2019-12-31 06:50:30
问题 I am trying to create a Kaplan-Meier plot with 95% confidence bands plus having the censored data in a table beneath it. I can create the plot, but not the table. I get the error message: Error in grid.draw(both) : object 'both' not found. library(survival) library(ggplot2) library(GGally) library(gtable) data(lung) sf.sex <- survfit(Surv(time, status) ~ sex, data = lung) pl.sex <- ggsurv(sf.sex) + geom_ribbon(aes(ymin=low,ymax=up,fill=group),alpha=0.3) + guides(fill=guide_legend("sex")) pl

Create a ggplot2 survival curve with censored table

与世无争的帅哥 提交于 2019-12-31 06:50:27
问题 I am trying to create a Kaplan-Meier plot with 95% confidence bands plus having the censored data in a table beneath it. I can create the plot, but not the table. I get the error message: Error in grid.draw(both) : object 'both' not found. library(survival) library(ggplot2) library(GGally) library(gtable) data(lung) sf.sex <- survfit(Surv(time, status) ~ sex, data = lung) pl.sex <- ggsurv(sf.sex) + geom_ribbon(aes(ymin=low,ymax=up,fill=group),alpha=0.3) + guides(fill=guide_legend("sex")) pl

Aligning and arranging charts in ggplot

心已入冬 提交于 2019-12-31 03:05:21
问题 I have two plots in ggplot with similar ranges on the axis that I would like to align. Using: library(grid) grid.newpage() grid.draw(rbind(ggplotGrob(g1), ggplotGrob(g2), size = "last")) where size='last' ensures the grids are aligned for x, I get a layout such as this: The top chart has an excessive vertical range for the simple row I want to depict. I would like to have an image more in keeping with the following: Or alternatively, with the g1 chart aligned below the axis of the g2 chart.

Remove some of the axis labels in ggplot faceted plots

六月ゝ 毕业季﹏ 提交于 2019-12-30 06:23:12
问题 I have created a plot like the one here with ggplot2 package and facet_wrap function, and I would like to suppress some of the x-axis text to make it more legible. For example, here it would be more legible if the x-axis scales appeared only on boxes D, F, H and J. How could I do that? Thanks in advance! EDIT : the reproducible code library(ggplot2) d <- ggplot(diamonds, aes(carat, price, fill = ..density..)) + xlim(0, 2) + stat_binhex(na.rm = TRUE) + theme(aspect.ratio = 1) d + facet_wrap(~

How to create a heat Map for each column in a table

两盒软妹~` 提交于 2019-12-25 09:25:39
问题 I would like to create a heat map showing the highest value in a colour maybe light blue and the lowest value in dark blue and different shades throughout the column. This should be on a column by column basis not on the full table. How would I get about doing this? Sample code: library(gtable) library(grid) library(gridExtra) g <- tableGrob(iris[1:4, 1:3]) g <- gtable_add_grob(g, grobs = rectGrob(gp = gpar(fill = NA, lwd = 2)), t = 2, b = nrow(g), l = 1, r = ncol(g)) g <- gtable_add_grob(g,

y-axis for each subplot using facet_grid

て烟熏妆下的殇ゞ 提交于 2019-12-24 07:58:55
问题 I can't get the answer to this question to work. What both me and that user want is to add axis ticks and labels to all columns when using facet_grid(). Display y-axis for each subplot when faceting When I run the reproducable example and the solution (after adding abc=as.data.frame(abc) to fix the initial error) I receive an error message Error in gtable_add_grob(g, grobs = list(segmentsGrob(1, 0, 1, 1), segmentsGrob(1, : Not all inputs have either length 1 or same length same as 'grobs I

How to arrange plots with shared axes?

删除回忆录丶 提交于 2019-12-24 03:41:37
问题 I am trying to create an arrangement of three scatterplots with shared axes and marginal histograms. This seems like it should be simple, but it's giving me fits. I have tried approaches with gridExtra and gtable, both of which have gotten the general arrangement like I want but with alignments and plot sizes that were off. There are many other posts related to this question and I have experimented with the answers given to many of them, especially answers from @baptiste here and here. The