Grid-DP-Jan25 2011
Purpose
To explore grid graphics object model
> library(grid) |
Let me produce this output and then use functions to modify the output
> grid.circle(name = "circles", x = seq(0.1, 0.9, length = 40), + y = 0.5 + 0.4 * sin(seq(0, 2 * pi, length = 40)), r = abs(0.1 * + cos(seq(0, 2 * pi, length = 40)))) |
Edit grid.circle
> suffix <- c("even", "odd") > for (i in 1:8) { + grid.circle(name = paste("circle.", suffix[i%%2 + 1], sep = ""), + r = (9 - i)/20, gp = gpar(col = NA, fill = grey(i/10))) + } |
Using TextGrob
> library(RColorBrewer) > cols <- brewer.pal(4, "Set1") > purpose <- paste("My purpose in life is \n ", " to create and run a ", + sep = "") > purpose <- paste(purpose, "high frequency trading desk in India", + sep = "") > label.1 <- textGrob(purpose, gp = gpar(col = "white"), just = "center") > label.2 <- textGrob("Radha Krishna Pendyala", gp = gpar(col = "white"), + just = "center") > layout <- grid.layout(1, 2, widths = unit(c(1, 1), c("null", + "grobwidth"), list(NULL, label))) > grid.newpage() > pushViewport(viewport(layout = layout)) > pushViewport(viewport(layout.pos.col = 2)) > grid.rect(gp = gpar(fill = cols[2])) > grid.draw(label.1) > popViewport() > pushViewport(viewport(layout.pos.col = 1)) > grid.rect(gp = gpar(fill = cols[1])) > grid.draw(label.2) > popViewport() |