r-grid

R tableGrob change format of row

£可爱£侵袭症+ 提交于 2019-11-29 23:21:53
问题 I have some relatively simple code to create a table for printing to a PDF: library(gridExtra) df <- head(iris) tableGrob(df, gp = gpar(fontsize = 8), rows = NULL) I'd like to make the last row the same format as the header row (bold, and darker gray background). I understand I can use gpar to control format of the entire table, but not sure how to just affect the last row. Thanks! 回答1: One option is to create a new table, and merge the two together, g1 <- tableGrob(iris[1:4, 1:3], rows=NULL)

R adding a datatable to a ggplot graph using viewPorts : Scaling the Grob

不羁岁月 提交于 2019-11-29 08:44:33
问题 I'm trying to add a data-table to a graph made in ggplot (similar to the excel functionality but with the flexibility to change the axis its on) I've had a few goes at it and keep hitting a problem with scaling so attempt 1) was library(grid) library(gridExtra) library(ggplot2) xta=data.frame(f=rnorm(37,mean=400,sd=50)) xta$n=0 for(i in 1:37){xta$n[i]<-paste(sample(letters,4),collapse='')} xta$c=0 for(i in 1:37){xta$c[i]<-sample((1:6),1)} rect=data.frame(xmi=seq(0.5,36.5,1),xma=seq(1.5,37.5,1

How to plot grid plots on a same page?

﹥>﹥吖頭↗ 提交于 2019-11-29 08:42:34
I am using a package ( treemap ) that uses grid package to produce a treemap. However, I would like to plot several of these treemaps together, to add different color schemes to these plots. tmPlot function uses grid.newpage function, which clears the graphics window. I have not found a way to save grid.newpage objects as you can do for ggplot2 objects. Is there a way to plot several grid.newpage objects to a same window? ## Example library(treemap) # load Gross national income data data(GNI2010) size <- aggregate(GNI ~ continent, GNI2010, sum) size <- size[with(size, order(GNI, decreasing = T

independently move 2 legends ggplot2 on a map

前提是你 提交于 2019-11-29 05:05:52
I want to independently move two legends on a map to save save and make the presentation nicer. Here is the data: ## INST..SUB.TYPE.DESCRIPTION Enrollment lat lng ## 1 CHARTER SCHOOL 274 42.66439 -73.76993 ## 2 PUBLIC SCHOOL CENTRAL 525 42.62502 -74.13756 ## 3 PUBLIC SCHOOL CENTRAL HIGH SCHOOL NA 40.67473 -73.69987 ## 4 PUBLIC SCHOOL CITY 328 42.68278 -73.80083 ## 5 PUBLIC SCHOOL CITY CENTRAL 288 42.15746 -78.74158 ## 6 PUBLIC SCHOOL COMMON NA 43.73225 -74.73682 ## 7 PUBLIC SCHOOL INDEPENDENT CENTRAL 284 42.60522 -73.87008 ## 8 PUBLIC SCHOOL INDEPENDENT UNION FREE 337 42.74593 -73.69018 ## 9

How to create a grid of spatial points

旧巷老猫 提交于 2019-11-29 03:06:09
问题 library(reshape2) library(data.table) library(dplyr) library(magrittr) library(ggplot2) library(scales) library(gstat) library(DescTools) library(sp) #I want a colorado grid# data("colorado.grid") #making cordinates into spatial points dataframe# coordinates(Gold_tracer_kri) <- ~ long_orig + lat_orig #attempt at kriging but no grid# lzn.kriged <- krige(Au ~ 1, Gold_tracer_kri, colorado.grid, model=lzn.fit) lzn.kriged %>% as.data.frame %>% ggplot(aes(long_orig=long_orig, lat_orig=lat_orig)) +

How to manage the t, b, l, r coordinates of gtable() to plot the secondary y-axis's labels and tick marks properly

狂风中的少年 提交于 2019-11-28 19:02:19
I am using facet_wrap and was also able to plot the secondary y-axis. However the labels are not getting plotted near the axis, rather they are plotted very far. I realise it all will get resolved if I understand how to manipulate the coordinate system of the gtable (t,b,l,r) of the grobs. Could someone explain how and what they actually depict - t:r = c(4,8,4,4) means what. There are many links for secondary yaxis with ggplot, however when nrow/ncol is more than 1, they fails. So please teach me the basics of grid geometry and grobs location management. Edit : the Code this is the final code

How to annotate ggplot2 qplot outside of legend and plotarea? (similar to mtext())

蓝咒 提交于 2019-11-28 12:03:46
I would like to annotate my plots with a filename. With plot() I used mtext : plot(1:10) mtext("File xy-12-34-56.csv", 4) How can I do that with ggplot2 and qplot or ggplot? It should not collide with the legend. I found the commands annotate and grid , but I could not get an annotation similar to mtext with these. As a workaround I could try watermarks , but perhaps you have a good hint for me. Kind regards, Jonas Update Looks like to achieve the result now we should use the following: library(ggplot2) library(grid) library(gridExtra) p <- qplot(data = mtcars, wt, mpg) grid.arrange(p, right =

Align grob at fixed top/center position, regardless of size

做~自己de王妃 提交于 2019-11-28 11:44:25
I have some table grobs, some long and some short. I'd like to draw these at the top/center of the page (with a small margin). From this answer , I got a helpful starting point, but the positioning is dependent on each grob's height. library(gridExtra) # fake data my_df <- data.frame(col1=rep('hello', 35), col2=round(rnorm(35), 3)) # list of grobs tg <- list(tableGrob(my_df[1:30, ]), tableGrob(my_df[31:35, ])) # this positions grobs at center top, but varies based on rows in table tg[[1]]$vp <- viewport(x = 0.5, y = unit(1,"npc") - 0.52 * grobHeight(tg[[1]])) tg[[2]]$vp <- viewport(x = 0.5, y

How to plot grid plots on a same page?

别来无恙 提交于 2019-11-28 01:55:55
问题 I am using a package ( treemap ) that uses grid package to produce a treemap. However, I would like to plot several of these treemaps together, to add different color schemes to these plots. tmPlot function uses grid.newpage function, which clears the graphics window. I have not found a way to save grid.newpage objects as you can do for ggplot2 objects. Is there a way to plot several grid.newpage objects to a same window? ## Example library(treemap) # load Gross national income data data

arrow() in ggplot2 no longer supported

醉酒当歌 提交于 2019-11-28 00:28:00
问题 Installed R 2.15.2 on a new machine and ggplot2. The grid package is no longer supported in this latest version of R, but ggplot2 uses grid for the arrow() function, as in these examples. http://docs.ggplot2.org/current/geom_segment.html Haven't been able to find a workaround. Any suggestions? 回答1: Maybe you think that grid is no more supported because of the message displayed on its CRAN page ? But if it is written that Package ‘grid’ was removed from the CRAN repository , it is because it