-
Notifications
You must be signed in to change notification settings - Fork 2.1k
position_dodge2 with NA values causes errors #2905
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Could you please turn this into a reprex (short for minimal reproducible example)? It's especially helpful for ggplot2, since it automatically generates and uploads the plots (or lack thereof), which makes it much easier to go through at a glance. If you've never heard of a reprex before, you might want to start by reading the tidyverse.org help page. Thanks |
If you're looking for a workaround, your code works if you filter on dates before plotting, and don't set limits in library(dplyr)
library(ggplot2)
library(tibble)
library(quantmod)
df <- yahoo %>%
as.data.frame() %>%
rownames_to_column() %>%
rename("time" = "rowname") %>%
mutate(time = as.Date(time))
l <- c(df$time[10],df$time[100])
df_filtered <- df %>%
filter(time >= l[1]) %>%
filter(time <= l[2])
ggplot(data = df_filtered) +
geom_boxplot(aes(x = time,
lower = QQQ.Close,
upper = QQQ.Open,
ymin = QQQ.Low,
ymax = QQQ.High,
middle = QQQ.Open),
stat = "identity") +
scale_x_date() Created on 2018-09-25 by the reprex package (v0.2.1.9000) |
I think this is a potential bug in library(ggplot2)
df <- data.frame(
x_date = as.Date(c("1999-01-01", NA)),
x_chr = c("char", NA),
x_num = c(1, NA),
y = 1
)
p <- ggplot(df, aes(y = y))
# these work
p + aes(xmin = x_date, xmax = x_date) + geom_errorbarh(position = "dodge")
#> Warning: Removed 1 rows containing missing values (geom_errorbarh). p + aes(xmin = x_chr, xmax = x_chr) + geom_errorbarh(position = "dodge2") # these fail
p + aes(xmin = x_date, xmax = x_date) + geom_errorbarh(position = "dodge2")
#> Error in if (df$xmin[i] >= df$xmax[i - 1]) {: missing value where TRUE/FALSE needed
p + aes(xmin = x_num, xmax = x_num) + geom_errorbarh(position = "dodge2")
#> Error in if (df$xmin[i] >= df$xmax[i - 1]) {: missing value where TRUE/FALSE needed Created on 2019-05-24 by the reprex package (v0.2.1) In the original dataset for this issue there weren't any Lines 132 to 143 in 1f6f0cb
|
I have one problem with geom_boxplot works. First I am using date type data and try not to plot all my data, only a part.
First I load my packages
I am using getSymbols to get my data
I shape my data to use it in ggplot
I set my date limits
Then I try to plot it
and I get error:
Error in if (df$xmin[i] >= df$xmax[i - 1]) { :
valor ausente donde TRUE/FALSE es necesario
i get this error using ggplot2 3.0.0. I try this code in ggplot2 2.2.1 and i don't get any error. As far i search this can be related to "position_dodge2".
The text was updated successfully, but these errors were encountered: