njtierney / naniar

Tidy data structures, summaries, and visualisations for missing data
http://naniar.njtierney.com/
Other
650 stars 54 forks source link

gg_miss_fct - fails with column not found #252

Closed LukasWallrich closed 4 years ago

LukasWallrich commented 4 years ago

I cannot use gg_miss_fct on my dataset because it says "Column x is unknown" even though the column clearly is in the dataset - and I can reproduce the error when subsetting the inbuilt riskfactors dataset. Any way to fix that / work around it? Many thanks!

Just to note: the example from the documentation using the full riskfactors dataset works without problems.

library(naniar)
z <- riskfactors[1:5,]
gg_miss_fct(x = z, fct = marital)
#> Error: Column `marital` is unknown

Created on 2020-03-05 by the reprex package (v0.3.0)

MireiaValle commented 4 years ago

Same is happening to me since today, 2 weeks ago it worked well.

lucharo commented 4 years ago

Same here, my code was working fine last time I checked but now it's broken, seems to be something to do with the grouping within the function as given by the traceback:

traceback() 17: stop(list(message = "Column CVD_status is unknown", call = NULL, cppstack = NULL)) 16: grouped_df_impl(data, unname(vars), drop) 15: grouped_df(groups$data, groups$group_names, .drop) 14: group_by.data.frame(., !!fct) 13: dplyr::group_by(., !!fct) 12: function_list[i] 11: freduce(value, _function_list) 10: _fseq(_lhs) 9: eval(quote(_fseq(_lhs)), env, env) 8: eval(quote(_fseq(_lhs)), env, env) 7: withVisible(eval(quote(_fseq(_lhs)), env, env)) 6: x %>% dplyr::mutate_at(vars(!!fct), .funs = coerce_fct_na_explicit) %>% dplyr::group_by(!!fct) %>% miss_var_summary() 5: gg_miss_fct(x = bio.unfiltered.CVD, fct = CVD_status) at EDA.R#92

lucharo commented 4 years ago

For those of you that need it to work urgently, I would simply run:

library(naniar)  
library(ggplot2)  

riskfactors %>%  
  dplyr::group_by(marital) %>%  
  miss_var_summary() %>%  
  ggplot(aes(marital,  
             variable,  
             fill = pct_miss)) +  
  geom_tile() +  
  viridis::scale_fill_viridis(name = "% Miss") +  
  theme_minimal() +  
  theme(axis.text.x = element_text(angle = 45,  
                                   hjust = 1))

Which was given by @njtierney in another issue and is pretty much the source code!

njtierney commented 4 years ago

Hi there!

It looks like this might have been an issue with some code I wrote back in the early days of naniar, that I think has now been fixed due to some kind help from the tidyverse team:

library(naniar)
z <- riskfactors[1:5,]
gg_miss_fct(x = z, fct = marital)

Created on 2020-05-05 by the reprex package (v0.3.0)

Can you confirm that this works, @LukasWallrich ?

Thanks for the reprex!