r-grid

R convert grid units of layout object to native

百般思念 提交于 2021-02-08 05:15:40
问题 My problem is somewhat related to Convert units from npc to native using grid in R . I'm trying to figure out the location of certain plot elements start in a ggplot2 object (axes, main plot, etc). I found the following code: rm(list = ls()) library(ggplot2) library(grid) library(gtable) # a dummy plot g <- ggplot(cars, aes(x = speed, y = dist)) + geom_point() g # a layout of each element obj <- ggplotGrob(g) l <- gtable:::gtable_layout(obj) grid:::grid.show.layout(l) All the information I

R convert grid units of layout object to native

北城余情 提交于 2021-02-08 05:14:35
问题 My problem is somewhat related to Convert units from npc to native using grid in R . I'm trying to figure out the location of certain plot elements start in a ggplot2 object (axes, main plot, etc). I found the following code: rm(list = ls()) library(ggplot2) library(grid) library(gtable) # a dummy plot g <- ggplot(cars, aes(x = speed, y = dist)) + geom_point() g # a layout of each element obj <- ggplotGrob(g) l <- gtable:::gtable_layout(obj) grid:::grid.show.layout(l) All the information I

use grid.arrange over multiple pages or marrangeGrob with a layout_matrix

ぃ、小莉子 提交于 2021-02-07 17:45:42
问题 i want to arrange plots with the following layout_matrix over multiple pages. rep. e.g. library(gridExtra) library(ggplot2) layout <- rbind(c(1,2,3,4), c(1,2,3,4), c(1,2,3,4), c(5,5,5,5)) p <- list() for(i in 1:15) { ifelse(i %% 5 > 0, p[[i]] <- ggplot(mtcars, aes(wt, mpg)) + geom_point() + ggtitle(paste("plot:",i)), p[[i]] <- tableGrob(mtcars[5:7,],rows = NULL) ) } if i have only one page: (easy) grid.arrange(grobs=p[1:5],layout_matrix=layout) if i want multiple pages: (i loose all my

How to make RASTER from irregular point data without interpolation

醉酒当歌 提交于 2021-02-05 05:21:14
问题 I was trying to make a raster image from an irregularly spaced point database. The data looks like- > head(s100_ras) x y z 1 267573.9 2633781 213.29545 2 262224.4 2633781 69.78261 3 263742.7 2633781 51.21951 4 259328.4 2633781 301.98413 5 264109.8 2633781 141.72414 6 255094.8 2633781 88.90244 I want these 'z' values within a mesh which I created by # Create a fine mesh grid my_mesh=expand.grid(seq(min(s100_ras$Y),max(s100_ras$Y),l=100), seq(min(s100_ras$X),max(s100_ras$X),l=100)) I also want

How do I create a “for” loop in r that assigns ggplots as an object without saving over them

谁说胖子不能爱 提交于 2021-01-29 07:42:57
问题 I'm using the grid and grid.Extra packages to have multiple ggplots on one grid, however, I need to make 28 ggplots in total, each one with a different y variable. Obviously the loop to make and save them as a variable is simple enough, but I need to save each plot as a different object. Currently I just have 28 of the same plot code with only the axis changed, but I know that there's a better way. My minimum code example: dattn <- ggplot()+ geom_boxplot( data = dat, mapping = aes(x = site, y

ggplot plot axis ticks and labels separately

耗尽温柔 提交于 2021-01-28 02:35:12
问题 I am looking for a way to create ticks and labels in different positions on a ggplot. Sample code #load libraries library(ggplot2) library(reshape2) #create data df <-data.frame(A=1:6,B=c(0.6,0.5,0.4,0.2,0.3,0.8),C=c(0.4,0.5,0.6,0.8,0.7,0.2),D=c("cat1","cat1","cat1","cat2","cat2","cat2")) df df1 <- melt(df,measure.vars=c("B","C")) #plot p <- ggplot()+ geom_bar(data=df1,aes(x=A,y=value,fill=variable),stat="identity")+ theme(axis.title=element_blank(),legend.position="none") print(p) In this

ggplot plot axis ticks and labels separately

让人想犯罪 __ 提交于 2021-01-27 21:30:46
问题 I am looking for a way to create ticks and labels in different positions on a ggplot. Sample code #load libraries library(ggplot2) library(reshape2) #create data df <-data.frame(A=1:6,B=c(0.6,0.5,0.4,0.2,0.3,0.8),C=c(0.4,0.5,0.6,0.8,0.7,0.2),D=c("cat1","cat1","cat1","cat2","cat2","cat2")) df df1 <- melt(df,measure.vars=c("B","C")) #plot p <- ggplot()+ geom_bar(data=df1,aes(x=A,y=value,fill=variable),stat="identity")+ theme(axis.title=element_blank(),legend.position="none") print(p) In this

Draw 3x3 square grid in R

纵饮孤独 提交于 2021-01-20 20:15:13
问题 I got a list of number (n=9) and would like to draw them out in a 3*3 square grid and each grid fill with corresponding number. How can I do this in R without installing additional package e.g. plotrix. Many thanks! 回答1: Here is a good solution using just base R, and outputting to a png. Note the default png device has equal width and height. png("magic_square.png") par(mar=c(.5,.5,.5,.5)) plot(x=df$x,y=df$y,pch=as.character(df$val), asp=1, xlim=c(0.5,3.5),ylim=c(0.5,3.5),xaxt="n",yaxt="n"

Draw 3x3 square grid in R

。_饼干妹妹 提交于 2021-01-20 20:14:30
问题 I got a list of number (n=9) and would like to draw them out in a 3*3 square grid and each grid fill with corresponding number. How can I do this in R without installing additional package e.g. plotrix. Many thanks! 回答1: Here is a good solution using just base R, and outputting to a png. Note the default png device has equal width and height. png("magic_square.png") par(mar=c(.5,.5,.5,.5)) plot(x=df$x,y=df$y,pch=as.character(df$val), asp=1, xlim=c(0.5,3.5),ylim=c(0.5,3.5),xaxt="n",yaxt="n"