r-grid

R: ggplot background gradient coloring

烈酒焚心 提交于 2020-05-25 07:42:46
问题 I would like to generate ggplot’s with gradient coloring, filling both plot panel and its background, as herein shown. As you can see the gradient background coloring encompasses both plot panel and its background. At the moment, only an "approximation" of the required solution is known to me: library(ggplot2) library(grid) library(gridExtra) reds <- c("#7B0664", "#E32219") g <- rasterGrob(reds, width = unit(1, "npc"), height = unit(1, "npc"), interpolate = TRUE) ggplot(data = economics, aes

R: ggplot background gradient coloring

雨燕双飞 提交于 2020-05-25 07:42:06
问题 I would like to generate ggplot’s with gradient coloring, filling both plot panel and its background, as herein shown. As you can see the gradient background coloring encompasses both plot panel and its background. At the moment, only an "approximation" of the required solution is known to me: library(ggplot2) library(grid) library(gridExtra) reds <- c("#7B0664", "#E32219") g <- rasterGrob(reds, width = unit(1, "npc"), height = unit(1, "npc"), interpolate = TRUE) ggplot(data = economics, aes

gtable: Put a black line around all cells in the table body

孤街醉人 提交于 2020-01-05 10:06:13
问题 I'm trying to put a relatively heavy line (say lwd = 2 size) around the body of a table using gridExtra . Here's a MWE slightly modified from this documentation page. gtable is doing the work under the hood but the documentation for gtable is thin; looking at the code didn't help much. g <- tableGrob(iris[1:4, 1:3], rows = NULL) separators <- replicate(1, segmentsGrob(x1 = unit(0,"npc")), simplify=FALSE) g <- gtable::gtable_add_grob(g, grobs = separators, t = 1, b = nrow(g), l = 1) g <-

gtable: Put a black line around all cells in the table body

我是研究僧i 提交于 2020-01-05 10:06:11
问题 I'm trying to put a relatively heavy line (say lwd = 2 size) around the body of a table using gridExtra . Here's a MWE slightly modified from this documentation page. gtable is doing the work under the hood but the documentation for gtable is thin; looking at the code didn't help much. g <- tableGrob(iris[1:4, 1:3], rows = NULL) separators <- replicate(1, segmentsGrob(x1 = unit(0,"npc")), simplify=FALSE) g <- gtable::gtable_add_grob(g, grobs = separators, t = 1, b = nrow(g), l = 1) g <-

Filter TC tracks (lat-lon points) over a specified gridbox

感情迁移 提交于 2020-01-05 08:43:12
问题 I am using R to filter Tropical cyclone tracks passing over a grid box. I have a csv file containing the tracks and convert them to a shapefile. I wanted to filter only the points with the same identifier (the "SN" column in the sample data below) that passed over a specified grid box (5N to 25N and 115E to 135 E). Below is the code that I am using and the link to the data. jtwc <- read.csv("1979-1993_TC.csv",header=T,sep=",") latmin <-5.00 latmax <- 25.00 lonmin <- 115.00 lonmax <- 135.00

R - put ggplot grid lines in foreground [duplicate]

六月ゝ 毕业季﹏ 提交于 2019-12-30 08:09:15
问题 This question already has answers here : Overlay grid rather than draw on top of it (3 answers) Closed last year . I would like to know if there is a way to let ggplot draw its grid lines in front of the plotted data. As far as I know, I can format almost everything easily by using theme() which works well so far. However, I don't find the option in which order the elements are drawn. I could introduce additional lines to the plot which need to be formatted (coordinates, line groups, etc.)

R YaleToolkit: How to change the font size of tick labels on the sparklines?

梦想与她 提交于 2019-12-29 18:44:32
问题 I'm using this function for some quick and easy sparklines with R but I can't seem to work out how to change the font size to avoid ugly overlaps of the y-axis tick labels. Here's my code (see below for a reproducible example): sparklines(gamma.df, sub=c(1:23),outer.margin = unit(c(2, 2, 2, 2), "cm")) and the resulting plot: I seem to be able to completely suppress the y-axis with sparklines(gamma.df, sub=c(1:23),yaxis=FALSE,outer.margin = unit(c(2, 2, 2, 2), "cm")) But what I really want is

Justification of multiple legends in ggmap/ggplot2

对着背影说爱祢 提交于 2019-12-28 05:58:38
问题 I am trying to make a map with two legends denoting shape and colour ("Type" and "Org" in the example below), and have the legends inset. I can place the legends, but I would like them to be left justified so that their left edges line up. I can't make them anything other than centred with respect to each other: require(ggplot2) require(ggmap) require(grid) require(mapproj) data <- data.frame(Org=rep(c("ABCDEFG","HIJKLMNOP","QRSTUVWX"),4) , Type=rep(c("Y","Z"),6), Lat=runif(12,48,54.5) , Long

Make a rectangular legend, with rows and columns labeled, in grid

a 夏天 提交于 2019-12-28 02:52:08
问题 I've got a ggplot where I'm mapping factors to both fill and alpha, like this: set.seed(47) the_data <- data.frame(value = rpois(6, lambda=20), cat1 = rep(c("A", "B"), each = 3), cat2 = rep(c("X", "Y", "Z"), 2)) ggplot(the_data, aes(y = value, x = cat2, alpha = cat1, fill = cat2)) + geom_bar(stat = "identity", position = "dodge") + scale_alpha_discrete(range = c(0.5, 1)) + theme_bw() The people I'm producing it for don't find the legend for alpha very clear. I think a good alternative would

How to create a heat Map for each column in a table

两盒软妹~` 提交于 2019-12-25 09:25:39
问题 I would like to create a heat map showing the highest value in a colour maybe light blue and the lowest value in dark blue and different shades throughout the column. This should be on a column by column basis not on the full table. How would I get about doing this? Sample code: library(gtable) library(grid) library(gridExtra) g <- tableGrob(iris[1:4, 1:3]) g <- gtable_add_grob(g, grobs = rectGrob(gp = gpar(fill = NA, lwd = 2)), t = 2, b = nrow(g), l = 1, r = ncol(g)) g <- gtable_add_grob(g,