ggplot2 - How can I override the ggplot function in R? -


i use theme_bw command in pretty of r plots, thinking of overriding ggplot function so:

# override ggplot function use theme_bw default ggplot <- function(...) {   ggplot(...) + theme_bw() } 

however, when this, interpreter complains, saying

error: evaluation nested deeply: infinite recursion / options(expressions=)? 

is there way specify ggplot inside function should original version of ggplot, not 1 wrote?

use :: operator specify want call version of function lives in ggplot2 package, not version created in global workspace. i.e. like

ggplot <- function(...) {   ggplot2::ggplot(...) + theme_bw() } 

should work (although haven't tested it!)

i have strong preference theme_bw(). way use theme_set() right after load package, e.g.

library("ggplot2"); theme_set(theme_bw()) 

which arguably easy , more idiomatic/transparent solution.


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -