r-grid

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

杀马特。学长 韩版系。学妹 提交于 2019-12-05 11:31:17
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), class = "haven_labelled"), dtotac = structure(c(-9, -9, -8), label = "DV: Total actual hours in all jobs

element replacement in grid unit vector

天涯浪子 提交于 2019-12-05 08:26:33
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 attributes. However, their offsprings unit.arithmetic and unit.list should also be considered solution to be

“zoom”/“scale” with coord_polar()

安稳与你 提交于 2019-12-05 03:23:21
I've got a polar plot which uses geom_smooth(). The smoothed loess line though is very small and rings around the center of the plot. I'd like to "zoom in" so you can see it better. Using something like scale_y_continuous(limits = c(-.05,.7)) will make the geom_smooth ring bigger, but it will also alter it because it will recompute with the datapoints limited by the limits = c(-.05,.7) argument. For a Cartesian plot I could use something like coord_cartesian(ylim = c(-.05,.7)) which would clip the chart but not the underlying data. However I can see no way to do this with coord_polar() Any

Find the perimeter of a subset of a near-regular grid of points

拟墨画扇 提交于 2019-12-05 01:28:48
问题 Let us consider a set of near-regular grids in 2-D. These grids are adjacent (neighbouring grids have one or more same vertices) to the neighbouring grids. Here are the sample of 10 grids with the coordinates of the vertices (longitude,latitude) are as follows A<- lon lat [,1] [,2] [1,] 85.30754 27.91250 [2,] 85.32862 27.95735 [3,] 85.34622 27.89880 [4,] 85.36732 27.94364 [5,] 85.34958 28.00202 [6,] 85.38831 27.98830 [7,] 85.38487 27.88508 [8,] 85.40598 27.92991 [9,] 85.42353 27.87134 [10,]

How to lengthen specific tick marks in facet gridded ggplot?

北战南征 提交于 2019-12-05 01:18:19
问题 I want longer tick marks for those with labels in a facet grid. So I worked through this attempt and tried to adapt it to facet gridded plots like so: Defining breaks and labels, minor and major: range.f <- range(unique(df1$weeks)) minor.f <- 1 # every 1 week, NOTE: range.f[2] should be divisible by minor.f! major.f <- 5 # every 5 weeks breaks.f <- seq(range.f[1], range.f[2], minor.f) every_nth.lt <- function (x, nth) {x[1:nth != 1] <- ""; x} # (lite version of https://stackoverflow.com/a

How to put a wordcloud in a grob?

∥☆過路亽.° 提交于 2019-12-04 16:47:53
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', 'romantic', 'shy', 'spiritual', 'spontaneous', 'sweet', 'thoughtful', 'warm') freqs <- c(134, 53, 0, 5

How to draw rectangle using grid package

假如想象 提交于 2019-12-04 10:09:09
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.theme("postscript", color=FALSE)) grid.newpage() pushViewport(viewport(x=0, width=.4, just="left"))

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-04 09:18:33
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 aspect ratios. While the viewport of interest (gray and with grid) fills the maximal area available

Arrangement of large number of plots and connect with lines in r

你说的曾经没有我的故事 提交于 2019-12-04 07:48:08
问题 I have a large number of small plots need to placed in a bigger plot canvase and arrange small plots into and connect them with lines. A small example will look like this: A to L are independent plots. The cordinate of their placement is given. plot grid coordinates: PlotgridX and plotgridY can decide when the small plot need to be centered plotcord <- data.frame ( plotname = c("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L"), plotgridX = c( 1.5, 2, 5, 5.5, 1.75, 5.25, 8 , 1 , 2, 3

grid.arrange from gridExtras exiting with “only 'grobs' allowed in 'gList'” after update

时光毁灭记忆、已成空白 提交于 2019-12-03 22:05:37
I just updated R, R Studio, and a bunch of packages including ggplot2 and gridExtras on my Mac. Now gridExtras is failing in basic plotting with the error: "only 'grobs' allowed in "gList"" Here's some code that should work but does not: library(ggplot2) p1 = qplot(1:10,rnorm(10)) p2 = qplot(1:10,rnorm(10)) library(gridExtra) grid.arrange(p1, p2, ncol=2, main = "Main title") This dumps out the following error: Error in gList(list(grobs = list(list(x = 0.5, y = 0.5, width = 1, height = 1, : only 'grobs' allowed in "gList" In addition: Warning message: In grob$wrapvp <- vp : Coercing LHS to a