2017-01-13 3 views
1

Ich benutze ggplot2 ziemlich regelmäßig, und ich muss sagen, dieses hat mich verwirrten.ggplot denkt, ästhetisch wurde nicht über `aes()` gemacht, aber es war

Script ist:

library(tidyverse) 

data_frame(value = rbinom(n = 100, size = 100, prob = 0.3)) %>% 
    ggplot(mapping = aes(x = value)) %>% 
    geom_histogram() 

sessionInfo() 

Ausgang ist:

> library(tidyverse) 
Loading tidyverse: ggplot2 
Loading tidyverse: tibble 
Loading tidyverse: tidyr 
Loading tidyverse: readr 
Loading tidyverse: purrr 
Loading tidyverse: dplyr 
Conflicts with tidy packages ------------------------------------------------------- 
filter(): dplyr, stats 
lag(): dplyr, stats 
> 
> data_frame(value = rbinom(n = 100, size = 100, prob = 0.3)) %>% 
+ ggplot(mapping = aes(x = value)) %>% 
+ geom_histogram() 
Error: Mapping must be created by `aes()` or `aes_()` 
> 
> sessionInfo() 
R version 3.3.2 (2016-10-31) 
Platform: x86_64-apple-darwin13.4.0 (64-bit) 
Running under: macOS Sierra 10.12.1 

locale: 
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 

attached base packages: 
[1] stats  graphics grDevices utils  datasets methods base  

other attached packages: 
[1] dplyr_0.5.0  purrr_0.2.2  readr_1.0.0  tidyr_0.6.0  tibble_1.2  
[6] ggplot2_2.2.1 tidyverse_1.0.0 

loaded via a namespace (and not attached): 
[1] Rcpp_0.12.8  assertthat_0.1 R6_2.2.0   grid_3.3.2  
[5] plyr_1.8.4  DBI_0.5-1  gtable_0.2.0  magrittr_1.5  
[9] scales_0.4.1  lazyeval_0.2.0 tools_3.3.2  munsell_0.4.3 
[13] colorspace_1.3-2 
+4

Warum '%>% ggplot (..)' dann '%>% geom _...' und nicht '%>% ggplot (..) + geom _...'? – Haboryme

Antwort

7

Versuchen Sie es mit einem Pluszeichen, ich diesen Fehler mindestens einmal pro Woche zu machen.

data_frame(value = rbinom(n = 100, size = 100, prob = 0.3)) %>% 
    ggplot(mapping = aes(x = value)) + 
    geom_histogram() 
Verwandte Themen