Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

histogram breaks when NAs are present #148

Closed
ste-fan opened this issue May 16, 2014 · 1 comment
Closed

histogram breaks when NAs are present #148

ste-fan opened this issue May 16, 2014 · 1 comment

Comments

@ste-fan
Copy link

ste-fan commented May 16, 2014

When trying to plot a histogram of a variable that contains NAs, I get:

library(ggvis)

df <- data.frame( var = c(NA, rnorm(100)) )

df %>%
  ggvis(~var) %>%
  layer_histograms()
## Guessing binwidth = 0.172 # range / 30
## Error in seq.default(round_any(range[1], size, floor), round_any(range[2],  : 
##   'from' cannot be NA, NaN or infinite

Getting rid of observations with NAs solves the problem.

library(dplyr)

df %>% filter(!is.na(var)) %>%
  ggvis(~var) %>%
  layer_histograms()
## Guessing binwidth = 0.172 # range / 30

Should that be done automatically? ggplot2 does not even complain about NAs and just plots, as if they weren't there.

library(ggplot2)

df %>% 
  ggplot(aes(var)) + 
  geom_histogram()
## stat_bin: binwidth defaulted to range/30. Use 'binwidth = x' to adjust this.
sessionInfo()
## R version 3.1.0 (2014-04-10)
## Platform: x86_64-pc-linux-gnu (64-bit)
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=de_DE.UTF-8        LC_COLLATE=en_US.UTF-8    
##  [5] LC_MONETARY=de_DE.UTF-8    LC_MESSAGES=en_US.UTF-8   
##  [7] LC_PAPER=de_DE.UTF-8       LC_NAME=C                 
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=de_DE.UTF-8 LC_IDENTIFICATION=C       
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] ggplot2_0.9.3.1 dplyr_0.2       ggvis_0.2.0.99 
## 
## loaded via a namespace (and not attached):
##  [1] assertthat_0.1.0.99 bitops_1.0-6        caTools_1.17       
##  [4] colorspace_1.2-4    digest_0.6.4        filehash_2.2-2     
##  [7] grid_3.1.0          gtable_0.1.2        httpuv_1.3.0       
## [10] labeling_0.2        magrittr_1.0.0      MASS_7.3-33        
## [13] munsell_0.4.2       parallel_3.1.0      plyr_1.8.1         
## [16] proto_0.3-10        Rcpp_0.11.1         reshape2_1.4       
## [19] RJSONIO_1.2-0.2     scales_0.2.4        shiny_0.9.1.9008   
## [22] stringr_0.6.2       tikzDevice_0.7.0    tools_3.1.0        
## [25] xtable_1.7-3       
@wch
Copy link
Contributor

wch commented May 16, 2014

We don't have consistent NA handling in ggvis. That's something we'll be working on for the next release (or perhaps the one after that).

@wch wch closed this as completed in 1988bab Jul 15, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants