How to change the default stat in ggplot2

I know how to change the default color on histograms to blue

update_geom_defaults("bar", list(fill = "blue"))

      

but how to change stat component. I tried

update_geom_defaults("bar", list(stat = "identity"))

      

but after trying a ggplot() + geom_bar(...)

I get an error Mapping a variable to y and also using stat="bin"

. How can I change the default settings?

I noticed that

> update_geom_defaults
function (geom, new) 
{
    g <- Geom$find(geom)
    old <- g$default_aes()
    aes <- defaults(new, old)
    g$default_aes <- eval(substitute(function(.) aes, list(aes = aes)))
}
<environment: namespace:ggplot2>

      

seems to only apply the update to aesthetics.

+3


source to share


1 answer


update_geom_defaults

and update_stat_defaults

are functions for changing the default aesthetic display. IFIIK. There is no function to change the default statistics, but you can easily complete the task like



geom_bar_i <- function(...) geom_bar(..., stat = "identity")
ggplot(mtcars, aes(x = am, y = vs)) + geom_bar_i()

      

+1


source







All Articles