Description Usage Arguments Computed variables Examples
View source: R/stat-propzero.R
stat_propzero()
calculates the proportion of zeros in y
for each unique
x
and uses geom_text()
by default to add annotations to the plot.
1 2 3 4 5 6 7 8 9 10 11 |
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
geom |
Override the default connection between |
position |
Position adjustment, either as a string, or the result of a call to a position adjustment function. |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
... |
Other arguments passed on to |
format.fun |
Function to format labels when using |
stat_propzero()
provides the following variables:
proportion of zeros
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | library(ggplot2)
## Generate some random zero-inflated data
n <- 100
p <- 0.123
y <- ifelse(rbinom(n, size = 1, prob = p) > 0, 0, rpois(n, lambda = 2))
df <- data.frame(x = rep(c("A", "B"), each = n / 2), y = y)
## Make plot
p <- ggplot(df, aes(x, y)) + geom_jitter(alpha = 0.2, width = 0.1)
p + stat_propzero()
## Use a different formatting function
p + stat_propzero(format.fun = scales::label_scientific())
p + stat_propzero(format.fun = function(x) format(x, digits = 1))
p + stat_propzero(format.fun = scales::label_percent(accuracy = 0.01))
## Adjust label position with `hjust` and `vjust`
p + stat_propzero(vjust = 3)
p + stat_propzero(hjust = 3)
p + stat_propzero(hjust = 3, vjust = 3)
## Using a different `geom` than text
## This will require mapping of the `propzero` stat to another aesthetic
## with `after_stat`.
p + stat_propzero(aes(col = after_stat(propzero)), geom = "point", size = 5)
p + stat_propzero(aes(size = after_stat(propzero)), geom = "point")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.