hafen / trelliscopejs

TrelliscopeJS R Package
https://hafen.github.io/trelliscopejs
Other
263 stars 36 forks source link

!is.nan(skw) && skw > 1.5 && all(x >= 0, na.rm = TRUE) #34

Open hathawayj opened 7 years ago

hathawayj commented 7 years ago

I get an error as pasted below when I run a trelliscope with facet_trelliscope. The same plot works with facet_wrap. I wish I had something more useful to show. I might be able to provide a clearer example if it is useful. What are skw and x in the check below?

facet_trelliscope(~Building_Code+Days) facet_wrap(~Building_Code+Days)

Error in if (!is.nan(skw) && skw > 1.5 && all(x >= 0, na.rm = TRUE)) { : missing value where TRUE/FALSE needed

hafen commented 7 years ago

The place in the code where this is happening is when it's doing a skewness test on each of your cognostics to determine whether its distribution should be shown on the log scale. You must have a variable that is behaving very strangely. I can maybe try to make this more robust without having a reproducible example, but if you can try to re-run your code omitting all variables in your data you are passing into ggplot() other than what is required for plotting. Then you can add variables in until you find the offending one.

clarkjoe commented 6 years ago

I am working with Trenton, and we also are getting this error in RStudio. Our data consists of an unique ID, Date, and Count. We are only building trelliscope panel function on the data itself, with no additional cognostics.

The code is the following:

bob %>%
  select(-features) %>%
  filter(prediction == 70) %>%
  gather("Date", "Count", `20140928`:`20180204`) %>%
  mutate(Date = ymd(Date)) %>%
  group_by(prediction) %>%
  filter(Count > 0) %>%
  nest() %>%
  mutate(
    #cogs = map_cog(data, ~ data_frame(
    #  mean = mean(.$Count)
    #)),
    panel = map_plot(data, ~ ggplot(., aes(x = Date, y = Count, group = AccountNumber)))
                       #geom_line(aes(alpha = .25)))
                       #theme_bw())
  ) %>%
  trelliscope("billybob5", self_contained = T, auto_cog = FALSE)

The following is our error:

Error in if (!is.nan(skw) && skw > 1.5 && all(x >= 0, na.rm = TRUE)) { : 
  missing value where TRUE/FALSE needed
trentonpulsipher commented 6 years ago

Ryan, we found a solution to our problem unrelated to your code. It had to do with how the data was being passed into the mutate/panel function. Please disregard Joseph's comment above. Thanks

hafen commented 6 years ago

It's interesting that @hathawayj also experienced this issue so I wonder if there is something we could be doing better to give a more clear error message. If I could get a reproducible example I could look into it.

david-jankoski commented 6 years ago

i've hit the same problem and think i have the root cause + a reprex for you. in my case, i can reproduce it always when

library("ggplot2")
library("trelliscopejs")

d <- 
  data.frame(

    # these are not important (i think)
    x = 1:100, y = rnorm(100),
    z = sample(letters[1:5], size = 100, replace = TRUE),

    # here is the culprit
    # set up a factor with 4 categories
    f = rep(LETTERS[1:4], each = 25),
    # column with NAs for the first 3 levels and a single constant 
    # value for the remaining factor level
    col_with_nas = c( rep(NA, 75), rep(42, 25) )
  )

# double check the setup
table(d$col_with_nas, d$f, useNA = "ifany")

#>          A  B  C  D
#>    42    0  0  0 25
#>    <NA> 25 25 25  0

# ggplot facet_warp works fine
ggplot(d, aes(x, y, colour = z)) +
  geom_point() +
  geom_line(aes(group = z)) +
  facet_wrap(~ f)

# facet_trelliscope breaks  
ggplot(d, aes(x, y, colour = z)) +
  geom_point() +
  geom_line(aes(group = z)) +
  trelliscopejs::facet_trelliscope( ~ f)

# outputs :
#
#> using data from the first layer
#> building display obj [=====================================------------------------------]  56% 5/9 eta: 1s
#> Error in if (!is.nan(skw) && skw > 1.5 && all(x >= 0, na.rm = TRUE) && : missing value where TRUE/FALSE needed

I think it is not that hard to write a short function that checks for such input column anomalies and signals a warning. Depending on your thoughts of course, i can try my hand at implementing a patch (have never done this before...).
Thank you for developing this wonderful package and all your other work!