r-grid

Arrange base plots and grid.tables on the same page

核能气质少年 提交于 2019-12-17 06:11:47
问题 I have 2 plots (created using Base graphics) and 2 data frames that I would like to combine onto one sheet in a PDF. I'm using grid.table to create a tableGrobs from my data frames. I'm having a lot of difficulty formatting the PDF output. In particular, I've been unsuccessful keeping all the objects on the same page. I want the right pannel to contain one graph, and the left panel to contain the other graph, and 2 tables below (landscape format). Currently my code is something like the

Bar charts connected by lines / How to connect two graphs arranged with grid.arrange in R / ggplot2

烂漫一生 提交于 2019-12-13 11:49:53
问题 At Facebook research, I found these beautiful bar charts which are connected by lines to indicate rank changes: https://research.fb.com/do-jobs-run-in-families/ I would like to create them using ggplot2. The bar-chart-part was easy: library(ggplot2) library(ggpubr) state1 <- data.frame(state=c(rep("ALABAMA",3), rep("CALIFORNIA",3)), value=c(61,94,27,10,30,77), type=rep(c("state","local","fed"),2), cumSum=c(rep(182,3), rep(117,3))) state2 <- data.frame(state=c(rep("ALABAMA",3), rep("CALIFORNIA

Plot gList side by side

你。 提交于 2019-12-12 21:15:02
问题 I have 2 gList objects (grid) that plots fine when I do grid.draw(plot1) grid.draw(plot2) But I want these to be side by side in a pdf. Something like pdf(test.pdf) par(mfrow=c(1,2)) plot(1:10) plot(10:1) dev.off But this doesn't work. 回答1: To arrange grid objects , you can use grid.layout within a viewport. here an example. pushViewport(plotViewport(layout=grid.layout(1, 2),gp=gpar(cex=2))) pushViewport(plotViewport(layout.pos.col=1)) grid.draw(getPlot()) popViewport() pushViewport

Output Venn gList object and Network plot side-by-side [duplicate]

假如想象 提交于 2019-12-12 11:11:35
问题 This question already has an answer here : Arrange base plots and grid.tables on the same page (1 answer) Closed 3 years ago . How can we plot Network plot ( igraph package plot ) and Venn diagram ( VennDiagram gList object ) side-by-side in one PDF page ? Tried to follow below solutions, didn't work: Plot gList side by side Plot 2 tmap objects side-by-side Side-by-side Venn diagram using Vennerable Here is an example, which plots them in two pages. I used grid.newpage() to make it plot in

How to put plots without any space using plot_grid?

无人久伴 提交于 2019-12-12 11:06:26
问题 I'm doing an arrangement of 2x2 plots. The plots share the same axis, so I want to put them together, e.g. This code: library(ggplot2) library(cowplot) Value <- seq(0,1000, by = 1000/10) Index <- 0:10 DF <- data.frame(Index, Value) plot <- ggplot(DF, aes(x = Index, y = Value)) + geom_line(linetype = 2) + theme(aspect.ratio = 0.5) plot_grid(plot, plot, plot, plot, align = "hv", ncol = 2) produces But I'd like something like: How can I achieve a similar result? 回答1: I think this is a case for

replacing elements of a ggplot inside a gtable: labels and gridlines

柔情痞子 提交于 2019-12-12 09:53:13
问题 I am learning to manipulate ggplot objects with gtable . [Here is a related question I asked: dismantling a ggplot with grid and gtable ] The present issue is: how to take various axis elements from one gtable and place them into another gtable in replacement of existing elements? and in particular: replace the vertical grid lines (and corresponding tickmarks). Below some code and figures. # Data df <- structure(list(Year = c(1950, 2013, 1950, 2013), Country = structure(c(1L, 1L, 2L, 2L),

Create a surface from “pre-gridded” points

女生的网名这么多〃 提交于 2019-12-12 04:23:42
问题 I have a large data.frame which has 3 variables Longitude , Latitude and Temp . The data is arranged so that it is regularly spaced on a "grid" of 1/4 degree - so that dput(head(dat)) gives: structure(list(Longitude = c(0.125, 0.375, 0.625, 0.875, 1.125, 1.375), Latitude = c(0.125, 0.125, 0.125, 0.125, 0.125, 0.125 ), Temp = c(25.2163, 25.1917, 25.1593, 25.125, 25.0908, 25.0612 )), .Names = c("Longitude", "Latitude", "Temp"), row.names = c(NA, 6L), class = "data.frame"). I am having problems

Add sub text to viewport

旧巷老猫 提交于 2019-12-11 11:58:21
问题 I would like to add sub text (a textGrob ) to a grid Viewport -- is this possible? I have figured out how to add sub text to a single chart: require(ggplot2) require(gridExtra) # make the data timeSeries <- data.frame(date = seq(as.Date("2001-01-01"), as.Date("2012-01-01"), by = "mon"), value = 1:133 + rnorm(133, 0, 10) ) # make the ggplots gpLine <- ggplot(timeSeries, aes(x = date, y = value)) + geom_line() gpBar <- ggplot(timeSeries, aes(x = date, y = value)) + geom_bar(stat = 'identity') #

Open plots in a null device

為{幸葍}努か 提交于 2019-12-11 09:22:39
问题 I'm using the treemap package and I'm happy with how tmPlot arranges plot rectangles, I want to extract the grid for my own different plots. An example is as follows: library(treemap) data(GNI2010) dat <- tmPlot(GNI2010, index=c("continent", "iso3"), vSize="population", vColor="GNI", type="value")[[1]][[1]] This way I can store the coordinates of the rectangles I want. The catch is that it produces a plot as well. I can see a couple of ways to prevent the plot from being produced: .Call("R_GD

Finding the angle and distance over a ggplot/grid in R

自作多情 提交于 2019-12-11 06:56:50
问题 I have made a ggplot using some A and B numeric values. (If possible can you give me the solution for grid too?) Such as: A B 2 3 3 7 4 8 5 9 6 2 7 1 Now from the points, lets say A1 and A2 as shown in diagram, I want to measure the angle and the distance covered from each point. I know how to calculate the distance (via euclidean distance formula) from one point and for angle it can be calculated as cross and dot product of the vectors. But I am facing the problem to code this and to