GG_denhist | R Documentation |
Plots a histogram with an empirical density curve and a vertical line at desired central tendency measure.
GG_denhist(
data,
var = NULL,
group = NULL,
vline = mean,
histogram_pars = NULL,
clean_name = T,
no_y_axis_values = T,
alpha = 0.2,
auto_fraction_bounary = T,
...
)
data |
(data.frame or something coercible into) A data frame or a vector. |
var |
(chr sclr) The name of the variable to use. Not needed if data is a vector. Not needed if data has 1 column. |
group |
(chr sclr) The name of the grouping variable to use. |
vline |
(chr sclr) Whether and how to plot vertical line(s) at some point(s. Set to NULL for none. Default is |
histogram_pars |
(list) Histogram pars |
clean_name |
(lgl) Wheter to call str_clean on the x axis label. |
no_y_axis_values |
(lgl) Hide numbers on the Y axis? |
alpha |
Alpha for density fit. |
... |
Any other params we can try to match, mainly for backwards compatibility with geom_histogram pars |
Automatically rescales the histogram and density fit so the heights match. Applies theme_bw
.
A ggplot2 object.
GG_denhist(iris, "Sepal.Length") #plot overall distribution
GG_denhist(iris, "Sepal.Length", vline = median) #use another central tendency
GG_denhist(iris, "Sepal.Length", group = "Species") #plot by group
#also accepts vectors
iris$Sepal.Length %>% GG_denhist
#also accepts 1-column data.frames, but throws a warning
GG_denhist(iris[1])
#warns you if some groups have no data
data.frame(x = c(1, 2, NA), y = c(1, 2, 3)) %>% GG_denhist("x", "y")
#warns you if grouping variable has missing data
data.frame(x = c(1, 2, 3), y = c(1, 2, NA)) %>% GG_denhist("x", "y")
#autodetect fractional data
runif(1000) %>% GG_denhist()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.