ProjectMOSAIC / ggformula

Provides a formula interface to 'ggplot2' graphics.
Other
39 stars 11 forks source link

get gf_histogramh() and gf_dhistogram() to handle stat() and one-sided formulas #107

Closed rpruim closed 6 years ago

rpruim commented 6 years ago

Seems to be working.

library(ggformula)
#> Loading required package: ggplot2
#> Loading required package: ggstance
#> 
#> Attaching package: 'ggstance'
#> The following objects are masked from 'package:ggplot2':
#> 
#>     geom_errorbarh, GeomErrorbarh
#> 
#> New to ggformula?  Try the tutorials: 
#>  learnr::run_tutorial("introduction", package = "ggformula")
#>  learnr::run_tutorial("refining", package = "ggformula")
example(gf_histogram)
#> 
#> gf_hst> x <- rnorm(1000)
#> 
#> gf_hst> gf_histogram(  ~ x, bins = 30)

#> 
#> gf_hst> gf_dhistogram( ~ x, bins = 30)

#> 
#> gf_hst> gf_dhistogram( ~ x, binwidth = 0.5, center = 0, color = "black")

#> 
#> gf_hst> gf_dhistogram( ~ x, binwidth = 0.5, boundary = 0, color = "black")

#> 
#> gf_hst> gf_dhistogram( ~ x, bins = 30) %>%
#> gf_hst+  gf_fitdistr(dist = "dnorm")  # see help for gf_fitdistr() for more info.

#> 
#> gf_hst> gf_histogram( ~ x, fill = ~ (abs(x) <= 2), boundary = 2, binwidth = 0.25)

#> 
#> gf_hst> gf_histogram( ~ Sepal.Length | Species, data = iris, binwidth = 0.25)
#> 
#> gf_hst> if (require(mosaicData)) {
#> gf_hst+   gf_histogram( ~ age, data = HELPrct, binwidth = 5, fill = "skyblue", color = "black")
#> gf_hst+   # bins can be adjusted left/right using center or boundary
#> gf_hst+   gf_histogram( ~ age, data = HELPrct,
#> gf_hst+                binwidth = 5, fill = "skyblue", color = "black", center = 42.5)
#> gf_hst+   gf_histogram( ~ age, data = HELPrct,
#> gf_hst+                 binwidth = 5, fill = "skyblue", color = "black", boundary = 40)
#> gf_hst+ }
#> Loading required package: mosaicData

#> 
#> gf_hst> gf_histogramh( ~ x, bins = 30)

#> 
#> gf_hst> gf_histogramh( x ~ ., bins = 30)

#> 
#> gf_hst> gf_histogramh( x ~ stat(density), bins = 30)

#> 
#> gf_hst> gf_dhistogramh(~ x, bins = 30)

#> 
#> gf_hst> gf_dhistogramh(x ~ ., bins = 30)

#> 
#> gf_hst> # better to use gf_histogramh() here, but this works
#> gf_hst> gf_dhistogramh(x ~ stat(count), bins = 30)

Created on 2018-07-23 by the reprex package (v0.2.0).