ggproto

Can you make geom_ribbon leave a gap for missing values?

本小妞迷上赌 提交于 2019-11-29 06:59:31
I am following up a discussion started at: How can I make geom_area() leave a gap for missing values? . It seems like geom_ribbon is not longer leaving gaps for missing values. Please try to execute the reproducible example in the attached link. I cannot get the answer described. Can you? Looks like a bug in ggplot2 , there seems to be a missing handle_na function that needs to be added as a part of a new unified way of dealing with NA values. Update: The first post here refined an entire new ggproto to fix this, but I realized that as a one-liner workaround you can just override the handle_na

How to determine the geom type of each layer of a ggplot2 object?

て烟熏妆下的殇ゞ 提交于 2019-11-29 02:06:50
As part of an effort to remove a specific geom from a plot I've already created (SO link here ), I'd like to dynamically determine the geom type of each layer of a ggplot2 object. Assuming I don't know the order in which I added layers, is there a way to dynamically find layers with a specific geom? If I print out the layers like I do below I can see that the layers are stored in a list, but I can't seem to access the geom type. library(ggplot2) dat <- data.frame(x=1:3, y=1:3, ymin=0:2, ymax=2:4) p <- ggplot(dat, aes(x=x, y=y)) + geom_ribbon(aes(ymin=ymin, ymax=ymax), alpha=0.3) + geom_line()

align points and error bars in ggplot when using `jitterdodge`

时光怂恿深爱的人放手 提交于 2019-11-28 10:31:11
问题 The reproducible data below contains 50 observations for each animal (cat and dog) for each season (Summer and Winter) for two covariates (cov1 and cov2) and their respective error estimates (SE). library(ggplot2); library(dplyr); library(tidyr) set.seed(123) dat <- data.frame(Season = rep(c("Summer", "Winter"), each = 100), Species = rep(c("Dog", "Cat", "Dog", "Cat"), each = 50), cov1 = sample(1:100, 200, replace = TRUE), cov1SE = rnorm(200), cov2 = sample(1:100, 200, replace = TRUE), cov2SE

Warning when defining factor: duplicated levels in factors are deprecated

做~自己de王妃 提交于 2019-11-28 09:08:58
I am having a little trouble with my radar chart in R. Even though the plot is fine I am getting the following warning: > source('~/.active-rstudio-document') Warning message: In `levels<-`(`*tmp*`, value = if (nl == nL) as.character(labels) else paste0(labels, : duplicated levels in factors are deprecated > radar Warning messages: 1: In `levels<-`(`*tmp*`, value = if (nl == nL) as.character(labels) else paste0(labels, : duplicated levels in factors are deprecated 2: In `levels<-`(`*tmp*`, value = if (nl == nL) as.character(labels) else paste0(labels, : duplicated levels in factors are

Split violin plot with ggplot2 with quantiles

六眼飞鱼酱① 提交于 2019-11-28 03:48:57
问题 In order to plot half densities, I am using the function described in this post: Split violin plot with ggplot2 However, when I want to draw the quantiles on the densities, like on a normal geom_violin() or geom_boxplot() , I obtain an error message. I would also be interested in adding the number of observations above each half density. Here is an example of what I would like to obtain: data("diamonds") library(ggplot2) # Function described in a previous post GeomSplitViolin <- ggproto(

Can you make geom_ribbon leave a gap for missing values?

社会主义新天地 提交于 2019-11-28 00:37:19
问题 I am following up a discussion started at: How can I make geom_area() leave a gap for missing values?. It seems like geom_ribbon is not longer leaving gaps for missing values. Please try to execute the reproducible example in the attached link. I cannot get the answer described. Can you? 回答1: Looks like a bug in ggplot2 , there seems to be a missing handle_na function that needs to be added as a part of a new unified way of dealing with NA values. Update: The first post here refined an entire

Hollow histogram or binning for geom_step

橙三吉。 提交于 2019-11-27 22:08:13
I would like to draw a hollow histogram that has no vertical bars drawn inside of it, but just an outline. I couldn't find any way to do it with geom_histogram . The geom_step + stat_bin combination seemed like it could do the job. However, the bins of geom_step + stat_bin are shifted by a half bin either to the right or to the left, depending on the step's direction= parameter value. It seems like it is doing its "steps" WRT bin centers. Is there any way to change this behavior so it would do the "steps" at bin edges? Here's an illustration: d <- data.frame(x=rnorm(1000)) qplot(x, data=d,

qqnorm and qqline in ggplot2

柔情痞子 提交于 2019-11-27 16:52:58
Say have a linear model LM that I want a qq plot of the residuals. Normally I would use the R base graphics: qqnorm(residuals(LM), ylab="Residuals") qqline(residuals(LM)) I can figure out how to get the qqnorm part of the plot, but I can't seem to manage the qqline: ggplot(LM, aes(sample=.resid)) + stat_qq() I suspect I'm missing something pretty basic, but it seems like there ought to be an easy way of doing this. EDIT: Many thanks for the solution below. I've modified the code (very slightly) to extract the information from the linear model so that the plot works like the convenience plot in

Warning when defining factor: duplicated levels in factors are deprecated

半城伤御伤魂 提交于 2019-11-27 02:44:12
问题 I am having a little trouble with my radar chart in R. Even though the plot is fine I am getting the following warning: > source('~/.active-rstudio-document') Warning message: In `levels<-`(`*tmp*`, value = if (nl == nL) as.character(labels) else paste0(labels, : duplicated levels in factors are deprecated > radar Warning messages: 1: In `levels<-`(`*tmp*`, value = if (nl == nL) as.character(labels) else paste0(labels, : duplicated levels in factors are deprecated 2: In `levels<-`(`*tmp*`,

Hollow histogram or binning for geom_step

非 Y 不嫁゛ 提交于 2019-11-26 23:07:48
问题 I would like to draw a hollow histogram that has no vertical bars drawn inside of it, but just an outline. I couldn't find any way to do it with geom_histogram . The geom_step + stat_bin combination seemed like it could do the job. However, the bins of geom_step + stat_bin are shifted by a half bin either to the right or to the left, depending on the step's direction= parameter value. It seems like it is doing its "steps" WRT bin centers. Is there any way to change this behavior so it would