5

I know how to change the default colour in bar charts blue

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

but how do I change the stat component. I tried

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

but after I attempt a ggplot() + geom_bar(...) I get the error message Mapping a variable to y and also using stat="bin". How do I actually change the defaults?

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.

1 Answer 1

3

update_geom_defaults and update_stat_defaults are functions to change the default aesthetic mapping.

As far as I know, there is no function to change the default stats, but you can easily do the job by, e.g.,

geom_bar_i <- function(...) geom_bar(..., stat = "identity")
ggplot(mtcars, aes(x = am, y = vs)) + geom_bar_i()
Sign up to request clarification or add additional context in comments.

1 Comment

For this special case, geom_bar() with stat = "identity", a dedicated geom exists in ggplot: geom_col().

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.