gtable

Figure caption scientific names + symbols in textGrob gtable

自古美人都是妖i 提交于 2019-12-01 08:51:57
First of all I would like to thank Sir Baptiste for helping me improve my R script by adding a caption at the bottom left the of the combined plots using gtable/textGrob as shown below: library(grid) library(gridExtra) library(ggplot2) p1 <- p2 <- ggplot() g1 <- ggplotGrob(p1) g2 <- ggplotGrob(p2) g <- rbind(g1, g2) caption <- textGrob("Figure 1. This is a caption", hjust=0, x=0) g <- gtable::gtable_add_rows(g, unit(2,"mm") + grobHeight(caption), -1) g <- gtable::gtable_add_grob(g, caption, nrow(g), l = 4, r = ncol(g)) grid.newpage() grid.draw(g) However, I want to add two more things: (1)

dismantling a ggplot with grid and gtable

徘徊边缘 提交于 2019-12-01 07:42:39
问题 I'm struggling to build a dual-axis plot based on ggplot objects. At baptiste's suggestion, I have broken down the problem into smaller parts. The present issue is: how to remove all of the data from the grobs , while keeping the axis, the axis labels, the axis tickmarks, and the grid lines? By 'data' I mean the data associated with geom_line() and geom_points() . The reason for wanting to do this is that in the process of building a dual-axis plot, I ran into the following problem: the grid

gtable_add_grob(): linesGrob() not displayed

狂风中的少年 提交于 2019-12-01 07:40:49
问题 Why are the lines (via linesGrob ) not drawn in the following plot? require(gtable) base <- gtable(widths=unit(rep(1, 2), "null"), heights=unit(rep(1, 3), "null")) grid.newpage() g <- 1 for(i in 1:3) { for(j in 1:2) { base <- gtable_add_grob(base, grobs=list(linesGrob(x=1:4, y=4:1), rectGrob(gp=gpar(fill="#FF0000")), textGrob(label=g)), i, j, name=1:3) g <- g+1 } } grid.draw(base) 回答1: Two reasons: the coordinates fall outside the viewport the rectGrob is drawn on top and masks it require

Figure caption scientific names + symbols in textGrob gtable

假装没事ソ 提交于 2019-12-01 06:09:45
问题 First of all I would like to thank Sir Baptiste for helping me improve my R script by adding a caption at the bottom left the of the combined plots using gtable/textGrob as shown below: library(grid) library(gridExtra) library(ggplot2) p1 <- p2 <- ggplot() g1 <- ggplotGrob(p1) g2 <- ggplotGrob(p2) g <- rbind(g1, g2) caption <- textGrob("Figure 1. This is a caption", hjust=0, x=0) g <- gtable::gtable_add_rows(g, unit(2,"mm") + grobHeight(caption), -1) g <- gtable::gtable_add_grob(g, caption,

aligning distinct non-facet plots in ggplot2 using Rpy2 in Python

末鹿安然 提交于 2019-11-30 12:33:27
I am combining two distinct plots into a grid layout with grid as suggested by @lgautier in rpy2 using python. The top plot is a density and and the bottom a bar graph: iris = r('iris') import pandas # define layout lt = grid.layout(2, 1) vp = grid.viewport(layout = lt) vp.push() # first plot vp_p = grid.viewport(**{'layout.pos.row': 1, 'layout.pos.col':1}) p1 = ggplot2.ggplot(iris) + \ ggplot2.geom_density(aes_string(x="Sepal.Width", colour="Species")) + \ ggplot2.facet_wrap(Formula("~ Species")) p1.plot(vp = vp_p) # second plot mean_df = pandas.DataFrame({"Species": ["setosa", "virginica",

Arrange common plot width with facetted ggplot 2.0.0 & gridExtra

核能气质少年 提交于 2019-11-29 20:24:45
问题 Since I have updated to ggplot2 2.0.0, I cannot arrange charts propperly using gridExtra. The issue is that the faceted charts will get compressed while other will expand. The widths are basically messed up. I want to arrange them similar to the way these single facet plots are: left align two graph edges (ggplot) I put a reproducible code library(grid) # for unit.pmax() library(gridExtra) plot.iris <- ggplot(iris, aes(Sepal.Length, Sepal.Width)) + geom_point() + facet_grid(. ~ Species) +

Text alignment and font size in gtable

独自空忆成欢 提交于 2019-11-29 16:04:40
My question relates to the answer by Baptiste that you can find here: https://stackoverflow.com/a/18667413/2072440 . That code does pretty what I want it to do. I would like to make two modifications. First, I would like to align the text in the first column to the left. Second, I would like to change the font of the text. I have tried to edit the line that describes the fill for the cells' background but that does not seem to impact the font and it only impacts the position of the boxes itself rather than the text in them. Thank you. It would be useful to review how the grid system works, in

ggplot2 2.1.0 broke my code? Secondary transformed axis now appears incorrectly

a 夏天 提交于 2019-11-29 07:28:14
Some time ago, I inquired about adding a secondary transformed x-axis in ggplot, and Nate Pope provided the excellent solution described at ggplot2: Adding secondary transformed x-axis on top of plot . That solution worked great for me, and I returned to it hoping it would work for a new project. Unfortunately, the solution doesn't work correctly in the most recent version of ggplot2 . Now, running the exact same code leads to a "clipping" of the axis title , as well as overlap of the tick marks and labels . Here is an example, with the problems highlighted in blue: This example can be

Reproduce a 'The Economist' chart with dual axis

痴心易碎 提交于 2019-11-29 02:27:43
I was trying to replicate this chart from The Economist (the one on the left). The chart plots the number of billionaires in Russia on the left y-axis and the number of billionaires in rest of the world on the right. Create the chart for Russian billionaires ( p1 ). Create the chart for the others ( p2 ). Combine p1 and p2 into a dual y-axis chart using the code by Kohske . Data: (content of billionaire.csv ) ,Russia,World 1996,0,423 1997,4,220 1998,1,221 1999,0,298 2000,0,322 2001,8,530 2002,6,466 2003,17,459 2004,25,562 2005,27,664 2006,33,760 2007,53,893 2008,87,1038 2009,32,761 2010,62,949

How to manage the t, b, l, r coordinates of gtable() to plot the secondary y-axis's labels and tick marks properly

狂风中的少年 提交于 2019-11-28 19:02:19
I am using facet_wrap and was also able to plot the secondary y-axis. However the labels are not getting plotted near the axis, rather they are plotted very far. I realise it all will get resolved if I understand how to manipulate the coordinate system of the gtable (t,b,l,r) of the grobs. Could someone explain how and what they actually depict - t:r = c(4,8,4,4) means what. There are many links for secondary yaxis with ggplot, however when nrow/ncol is more than 1, they fails. So please teach me the basics of grid geometry and grobs location management. Edit : the Code this is the final code