R programming ggvis histogram verses hist - How to size the buckets, and define X axis spacing (ticks) -
i learning use ggvis , wanted understand how create equivalent histogram produced hist. specifically, how set bin widths , upper , lower bounds of x in ggvis histograms? missing?
question: how ggvis histogram output match hist output?
let me provide example:
require(psych) require(rcurl) require(ggvis) if ( !exists("impact") ) { url <- "https://dl.dropboxusercontent.com/u/8272421/stat/stat_one.txt" mycsv <- geturl(url, ssl.verifypeer = false) impact <- read.csv(textconnection(mycsv), sep = "\t") impact$subject <- factor(impact$subject) } describe(impact) hist(impact$verbal_memory_baseline, main = "distribution of verbal memory baseline scores", xlab = "score", ylab = "frequency")
ok, lets try , reproduce ggvis... output not match...
impact %>% ggvis( x = ~verbal_memory_baseline, fill := "white") %>% layer_histograms(width = 5) %>% add_axis("x", title = "score") %>% add_axis("y", title = "frequency")
how ggvis output match hist output?
> sessioninfo() r version 3.2.2 (2015-08-14) platform: x86_64-apple-darwin13.4.0 (64-bit) running under: os x 10.11.2 (el capitan) 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] psych_1.5.6 knitr_1.11 ggvis_0.4.2.9000 setwidth_1.0-4 colorout_1.1-1 vimcom_1.2-3 loaded via namespace (and not attached): [1] rcpp_0.12.0 digest_0.6.8 dplyr_0.4.3.9000 assertthat_0.1 mime_0.3 [6] r6_2.1.1 jsonlite_0.9.16 xtable_1.7-4 dbi_0.3.1 magrittr_1.5 [11] lazyeval_0.1.10.9000 rstudioapi_0.3.1 rmarkdown_0.7 tools_3.2.2 shiny_0.12.2 [16] httpuv_1.3.3 yaml_2.1.13 parallel_3.2.2 rsconnect_0.4.1.4 mnormt_1.5-3 [21] htmltools_0.2.6
try
impact %>% ggvis( x = ~verbal_memory_baseline, fill := "white") %>% layer_histograms(width = 5, boundary = 5) %>% add_axis("y", title = "frequency") %>% add_axis("x", title = "score", ticks = 5)
which gives:
the official documentation bit cryptic how boundary
, center
works. have @ datacamp's how make histogram ggvis in r
the
width
argument set bin width 5, bins start , end? can usecenter
orboundary
argument this.center
should refer 1 of bins’ center value, automatically determines other bins location.boundary
argument specifies boundary value of 1 of bins. here again, specifying single value fixes location of bins. these 2 arguments specify same thing in different way, should set @ 1 ofcenter
orboundary
.
if want same result using center
instead of boundary
try:
impact %>% ggvis( x = ~verbal_memory_baseline, fill := "white") %>% layer_histograms(width = 5, center = 77.5) %>% add_axis("y", title = "frequency") %>% add_axis("x", title = "score", ticks = 5)
here specify center of bin (77.5) , determines others automatically
Comments
Post a Comment