r-grid

exact positioning of plots with grid.layout

偶尔善良 提交于 2019-12-11 04:58:11
问题 I have two lattice plots. I need to position one above the other, and I need exactly .5" of vertical space between them. My thought is to use grid.layout to specify a three-row layout, with the middle row being exactly .5" high. Then I can print one plot to the top row and the other plot to the bottom row. It's almost working. The problem is that I can't get the middle row to be exactly .5" high. Here's a minimal example: pdf(file='example.pdf', height=12) # Create layout and viewports

convert textGrob to imageGrob/rasterGrob?

ε祈祈猫儿з 提交于 2019-12-10 20:09:59
问题 Apologies if this is very straightforward. Actually I hope it will be! I am trying to dynamically create images from text which I can then resize and plot (either stretched or squashed) to produce a motif-type graph. I started out using images (which I'd generated using png() and ggplot() ) and plotting them as annotation_custom() require(ggplot2) require(grid) require(gridExtra) qplot(c(0,10),c(0,10)) + annotation_custom(rasterGrob(image=readPNG("1999.png"),x=0,y=0,height=1,width=1,just=c(

Logarithmic grid for plot with 'ggplot2'

左心房为你撑大大i 提交于 2019-12-10 17:39:06
问题 I am trying to create a plot with logarithmically spaced grids using ggplot2 just like in the below figure. I get equidistant grids, but not log spaced ones. I know I am missing some parameter which I don't seem to get as of now. I have seen a lot of questions on the topic like Pretty ticks for log normal scale using ggplot2 (dynamic not manual), but do not solve the problem I am looking for. set.seed(5) x <- rlnorm(1000, meanlog=3.5, sdlog=1) y <- rlnorm(1000, meanlog=4.0, sdlog=1) d <- data

Multiple leaflets in a grid

对着背影说爱祢 提交于 2019-12-10 16:24:52
问题 I have 4 leaflet objects: A, B, C, D. I would like to plot them in a 2 by 2 grid, but I have been having a difficult time trying to do this. My initial thought was to use ggplot and facet_grid, but ggplot does not know how to deal with objects of class leaflet. I would appreciate the help! 回答1: Leaflets (or any other htmlwidgets) can be combined with htmltools::tagList . In this case, a simple html table can handle the layout: library(htmltools) leaflet_grid <- tagList( tags$table(width =

“zoom”/“scale” with coord_polar()

本小妞迷上赌 提交于 2019-12-10 02:21:46
问题 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

How do you relate ggplot2 grobs back to the data?

不问归期 提交于 2019-12-09 04:25:39
问题 Given a ggplot of, for example, points, how would you find out the row of data that a given point corresponded to? A sample plot: library(ggplot2) (p <- ggplot(mtcars, aes(mpg, wt)) + geom_point() + facet_wrap(~ gear) ) We can get the grobs that contain points with grid.ls + grid.get . grob_names <- grid.ls(print = FALSE)$name point_grob_names <- grob_names[grepl("point", grob_names)] point_grobs <- lapply(point_grob_names, grid.get) This last variable contains details of the x-y coordinates,

Arrange plots that have subplots called from functions on grid in matplotlib

南楼画角 提交于 2019-12-09 04:11:31
I am looking for something similar to arrangeGrob in R: I have a function (say, function FUN1 ) that creates a plot with subplots. The number of subplots FUN1 creates may vary and the plot itself is quite complex. I have two other functions FUN2 and FUN3 which also create plots of varying structure. Is there a simple way to define/arrange an overall GRID , for example a simple 3 rows 1 column style and simply pass FUN1 --> GRID(row 1, col 1) FUN2 --> GRID(row 2, col 1) FUN3 --> GRID(row 3, col 1) afterwards such that the complicated plot generated by FUN1 gets plotted in in row 1, the plot

How to have a clickable picture in a PDF created using pictureGrob?

◇◆丶佛笑我妖孽 提交于 2019-12-08 12:04:32
问题 I create a simple plot and have a picture actually an SVG icon as follows: library(ggplot2); library(grid); library(gridExtra) facebookGrob <- gTree(children=gList(pictureGrob(readPicture("inst/svg/facebook2.svg")))) p1 <- ggplot() + ggplot2::annotation_custom(facebookGrob, xmin=1.8, xmax=3.2, ymin=-0.6, ymax=1) final <- arrangeGrob(p1,...,) ggsave(filename='output.pdf',plot=final,...) Is there any way to generate a clickable link on top of this SVG icon in the final PDF? 回答1: the tikzDevice

Arrange plots that have subplots called from functions on grid in matplotlib

泄露秘密 提交于 2019-12-08 05:30:25
问题 I am looking for something similar to arrangeGrob in R: I have a function (say, function FUN1 ) that creates a plot with subplots. The number of subplots FUN1 creates may vary and the plot itself is quite complex. I have two other functions FUN2 and FUN3 which also create plots of varying structure. Is there a simple way to define/arrange an overall GRID , for example a simple 3 rows 1 column style and simply pass FUN1 --> GRID(row 1, col 1) FUN2 --> GRID(row 2, col 1) FUN3 --> GRID(row 3,

color grid cells in the United States and Canada

不打扰是莪最后的温柔 提交于 2019-12-08 03:36:40
问题 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) {