r-grid

How to create plots dynamically in grid.arrange in R?

岁酱吖の 提交于 2019-12-07 19:18:24
问题 I have a function get.single.plot , which takes one character argument and returns a ggplot2 plot object. I would like to build a grid.arrange object with n plots on it, where the n is the size of vector of (mentioned) character arguments. E.g., I woould like something like this to work: character.argument.vector <- c("12", "1", "2") grid.arrange(unlist(lapply(character.argument.vector, function(n) get.single.plot(n))), ncol = 1) Such thing does not work - I receive the following information:

marrangeGrob giving error for nrow

醉酒当歌 提交于 2019-12-07 09:30:07
问题 I'm trying to create a bunch of ggplot2 plots using a for loop and then saving them on a multi-page pdf document, and I'm having trouble with marrangeGrob. Here's some example code: Plots <- list() Plots[[1]] <- qplot(mtcars$mpg, mtcars$wt) Plots[[2]] <- qplot(mtcars$cyl, mtcars$wt) Plots[[3]] <- qplot(mtcars$mpg, mtcars$qsec) Plots[[4]] <- qplot(mtcars$cyl, mtcars$drat) # install.packages("gridExtra", dependencies = TRUE) library(gridExtra) MyPlots <- do.call(marrangeGrob, c(Plots, nrow = 1,

create hexagonal cells grid using lat/lon coordinates

那年仲夏 提交于 2019-12-07 08:21:51
问题 I would like to create a spatial grid with hexagonal cells using WGS84 coordinates (ie cells defined by 2 coordinates X=Latitude and Y=Longitude) So, this is what I was thinkin about : library(ggplot2);library(hexbin) X<-seq(-10,20,by=0.1) # create coordinates vectors X and Y Y<-seq(35,65,by=0.1) z<-rnorm(301,0.5,1) df<-as.data.frame(cbind(X,Y,z)) # create data frame with a z value for each cells (X,Y) pl<-ggplot2(data=mat,aes(x=X,y=Y,z=z))+stat_summury_hex(fun=function(x) sum(x)) plot(pl)

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),

element replacement in grid unit vector

纵然是瞬间 提交于 2019-12-07 04:08:34
问题 I've been baffled by this a few times already, so here's a made-up question for others who might stumble upon the same problem. Consider this grid unit vector, a = unit(1:3, c("cm", "in", "npc")) I want to replace some elements with new values. The natural approach would be, a[1] = unit(2,"pt") a # [1] 2cm 2in 3npc Something went wrong: only the numeric value was changed, not the unit. Why? What to do? Edit: As pointed out in one answer below, such units are just numeric vectors with

How to put a wordcloud in a grob?

旧街凉风 提交于 2019-12-06 12:13:13
问题 I've created a simple wordcloud: require(wordcloud) words <- c('affectionate', 'ambitious', 'anxious', 'articulate', 'artistic', 'caring', 'contented', 'creative', 'cynical', 'daring', 'dependable', 'easygoing', 'energetic', 'funny', 'generous', 'genuine', 'goodlistener', 'goodtalker', 'happy', 'hardworking', 'humerous', 'impulsive', 'intelligent', 'kind', 'loyal', 'modest', 'optimistic', 'outgoing', 'outrageous', 'passionate', 'perceptive', 'physicallyfit', 'quiet', 'rational', 'respectful',

color grid cells in the United States and Canada

為{幸葍}努か 提交于 2019-12-06 06:24:28
I would like to color grid cells in the United States and Canada. My goal is very similar to this question: R Plot Filled Longitude-Latitude Grid Cells on Map However, that question only deals with the United States and I cannot figure out how to add Canada. I was able to draw a map of the U.S. and Canada by modifying code found here: https://groups.google.com/forum/#!topic/ggplot2/KAKhoE0GO4U library(ggplot2) library(rgeos) library(maps) library(maptools) PolygonCoords <- function(polygon) { polygons <- polygon@Polygons coords.list <- lapply(seq_along(polygons), function(i) { # Extract the

How to draw rectangle using grid package

我的未来我决定 提交于 2019-12-06 05:45:48
问题 I need to draw a rectangle on my diagram to highlight different changes. I need to use grid package. I tried to use the grid.rect but it doesn't work. I want that my rectangle looks like on the picture. On the left part of the picture you can see my diagram and of the right part of the picture I've added the rectangle (in Paint) like I want it will be. library(grid) library(lattice) library(sandwich) data("Investment") Investment <- as.data.frame(Investment) trellis.par.set(theme = canonical

How do I manually fit a viewport with a fixed aspect ratio into its parent such that no space is wasted like ggplot can do?

浪子不回头ぞ 提交于 2019-12-06 02:52:10
问题 I have a viewport which has to have a fixed aspect ratio as it has to have equal distance between x and y units in its native coordinate system. I want to fit this viewport into a parent viewport such that it will scale to the largest extent possible, but maintains its aspect ratio. Using the grid unit 'snpc', I was able to maintain the aspect ratio, though I could not reach the largest extent possible. See my code below, which prints out what I have archieved so far at four different device

create hexagonal cells grid using lat/lon coordinates

有些话、适合烂在心里 提交于 2019-12-05 19:38:13
I would like to create a spatial grid with hexagonal cells using WGS84 coordinates (ie cells defined by 2 coordinates X=Latitude and Y=Longitude) So, this is what I was thinkin about : library(ggplot2);library(hexbin) X<-seq(-10,20,by=0.1) # create coordinates vectors X and Y Y<-seq(35,65,by=0.1) z<-rnorm(301,0.5,1) df<-as.data.frame(cbind(X,Y,z)) # create data frame with a z value for each cells (X,Y) pl<-ggplot2(data=mat,aes(x=X,y=Y,z=z))+stat_summury_hex(fun=function(x) sum(x)) plot(pl) But doing this does not provide what I wanted. So, my question is : how to do a spatial grid with