grob

R ggplot2: change colour of font and background in facet strip?

蹲街弑〆低调 提交于 2020-02-27 07:42:44
问题 I am trying to customize a ggplot2 plot containing facets, and would like to change both the colour of the facet strip, as well as the colour of the font. I found some code to change the strip.background colour, but was not able to modify it to change also the font color... any idea? What I got so far: library(ggplot2) library(grid) p <- ggplot(mpg, aes(displ, cty)) + geom_point() + facet_grid(drv ~ cyl) + ggtitle("How to change coloour of font in facet strip?") g <- ggplot_gtable(ggplot

R ggplot2: annotation_custom of raster grob does not plot

一笑奈何 提交于 2020-01-14 14:45:07
问题 UPDATE Turns out it was an issue of not being able to produce raster graphics over a remote desktop connection. I want to insert an image from file into a plot made with ggplot2. This question has already been asked here (Inserting an image to ggplot2) but for me the accepted answer produces a plot devoid of any image. There are no errors or warnings: the axes, grid, and points all plot just fine but there's no R logo (exported plot; I couldn't upload an image here). Code below: library

R ggplot2: annotation_custom of raster grob does not plot

蹲街弑〆低调 提交于 2020-01-14 14:45:07
问题 UPDATE Turns out it was an issue of not being able to produce raster graphics over a remote desktop connection. I want to insert an image from file into a plot made with ggplot2. This question has already been asked here (Inserting an image to ggplot2) but for me the accepted answer produces a plot devoid of any image. There are no errors or warnings: the axes, grid, and points all plot just fine but there's no R logo (exported plot; I couldn't upload an image here). Code below: library

Remove white space between plots and table in grid.arrange

那年仲夏 提交于 2019-12-30 04:58:19
问题 I would like to remove the large spacing that is inserted by default between the plots and the table in a grid.arrange, as shown in the MWE hereafter: require(ggplot2) require(gridExtra) list1=data.frame(mtcars[1:3, ]) # Dummy data p1 = ggplot(list1, aes(mpg,cyl)) + geom_point() # Dummy plot p2 = ggplot(list1, aes(disp,hp)) + geom_point() # Dummy plot plots <- arrangeGrob(p1, p2,nrow=2) table <- tableGrob(list1) grid.arrange(plots, table) I suspect this behaviour is due to the tableGrob, but

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

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

我的未来我决定 提交于 2019-12-22 00:04:25
问题 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

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

本秂侑毒 提交于 2019-12-20 01:34:49
问题 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",

How to place grobs with annotation_custom() at precise areas of the plot region?

大兔子大兔子 提交于 2019-12-17 04:55:06
问题 I am trying to reproduce the following [base R] plot with ggplot2 I have managed most of this, but what is currently baffling me is the placement of the line segments that join the marginal rug plot on the right of the plot with the respective label. The labels have been draw (in the second figure below) via anotation_custom() and I have used @baptiste's trick of turning off clipping to allow drawing in the plot margin. Despite many attempts I am unable to place segmentGrobs() at the desired

How to apply a clipping mask to geom in a ggplot?

丶灬走出姿态 提交于 2019-12-10 12:45:19
问题 I am trying to apply a clipping mask to a geom from a ggplot to mask part of the data, but keep the axis, the grid, other geoms and the legend visible. I do not want to create a specific plot, and therefore I am not looking for a work-around with polygons masking some parts of the plot. This is the kind of design I would like to emulate (the mask, not necessarily theme, I now how to do that): (source) See also this example One could argue that I could filter the data that is not contained in

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

雨燕双飞 提交于 2019-12-07 04:51:35
问题 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),