r-grid

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

我是研究僧i 提交于 2019-12-03 16:51:07
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",3)), value=c(10,30,7,61,94,27), type=rep(c("state","local","fed"),2), cumSum=c(rep(117,3), rep(182,3)

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

风格不统一 提交于 2019-12-03 16:34:55
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,] 85.44466 27.91616 [11,] 85.42698 27.97456 [12,] 85.46567 27.96081 [13,] 85.48334 27.90239 [14,] 85.50437

How to control font size in png?

帅比萌擦擦* 提交于 2019-12-03 13:42:43
问题 I am trying to make figures for a manuscript, that should be written with MS Word, which does not accept figures in pdf format. The journal asks first draft with figures embedded in the Word file. These figures should have resolution minimum of 300 dpi and have a width of either 169 mm or 81 mm (two/one column). I notice that when I specify the resolution of the picture to 300 (res = 300), the font size is bound to this value. This works fine with some figures (the first example, example.png)

Add a footnote citation outside of plot area in R?

£可爱£侵袭症+ 提交于 2019-12-03 02:42:40
问题 I'd like to add a footnote citation to my 3-panel facet grid plot produced in R. It's a footnote to credit the data source. I'd ideally like to have it below and external to all three axes---preferably in the lower left. I'm using ggplot2 and also ggsave() . This means I can't use grid.text() -based solutions, because that only draws on the x11() window, and can't be added to the ggplot object. Using instead png() ...code... dev.off() does not appear to be an option because I need ggsave 's

How do you relate ggplot2 grobs back to the data?

邮差的信 提交于 2019-12-03 00:14:15
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, and pointsize, etc. (try unclass(point_grobs[[1]]) ), but it isn't obvious how I get the row of data

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

不想你离开。 提交于 2019-12-02 18:12:04
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.5, 6, 7.5), plotgridY = c( 3, 3, 3, 3, 2 , 2, 2, 2 , 1, 1, 1, 1)) plotname plotgridX plotgridY 1 A 1

Add a footnote citation outside of plot area in R?

人走茶凉 提交于 2019-12-02 16:17:13
I'd like to add a footnote citation to my 3-panel facet grid plot produced in R. It's a footnote to credit the data source. I'd ideally like to have it below and external to all three axes---preferably in the lower left. I'm using ggplot2 and also ggsave() . This means I can't use grid.text() -based solutions, because that only draws on the x11() window, and can't be added to the ggplot object. Using instead png() ...code... dev.off() does not appear to be an option because I need ggsave 's resizing parameters, and find this command produces better, clearer prints (that are also much faster,

Adjust hexbin legend breaks

橙三吉。 提交于 2019-12-02 13:16:47
问题 In this example of a hexbin plot, the legend on the right has 10 levels/classes/breaks. Does anyone know how to change the number of levels? Say I want to change it to 5 or something. library(hexbin) x=rnorm(1000, mean = 50, sd = 1) y=rnorm(1000, mean = 30, sd = 0.5) df <- data.frame(x,y) #plot(df) hb <- hexbin(x=df$x, df$y) #hb <- hexbin(x=df$x, df$y,xbins=30) #plot(hb) gplot.hexbin(hb) 回答1: Like this? gplot.hexbin(hb,colorcut=5) And here's approximately the same thing using ggplot . library

Combining grid_arrange_shared_legend() and facet_wrap_labeller() in R

强颜欢笑 提交于 2019-12-02 05:20:11
问题 I am trying to combine grid_arrange_shared_legend() and facet_wrap_labeller() in R. More specifically, I want to draw a figure including two ggplot figures with multiple panels each and have a common legend. I further want to italicize part of the facet strip labels. The former is possible with the grid_arrange_shared_legend() function introduced here, and the latter can be achieved with the facet_wrap_labeller() function here. However, I have not been successful in combining the two. Here's

Combining grid_arrange_shared_legend() and facet_wrap_labeller() in R

可紊 提交于 2019-12-02 01:06:14
I am trying to combine grid_arrange_shared_legend() and facet_wrap_labeller() in R. More specifically, I want to draw a figure including two ggplot figures with multiple panels each and have a common legend. I further want to italicize part of the facet strip labels. The former is possible with the grid_arrange_shared_legend() function introduced here , and the latter can be achieved with the facet_wrap_labeller() function here . However, I have not been successful in combining the two. Here's an example. library("ggplot2") set.seed(1) d <- data.frame( f1 = rep(LETTERS[1:3], each = 100), f2 =