Disable cowplot default for ggplots

后端 未结 2 1841
萌比男神i
萌比男神i 2021-02-19 19:00

The ggplot2 add-on package, cowplot, has a nice function for plotting multiple plots called plot_grid(). Here\'s plot_grid()

2条回答
  •  梦毁少年i
    2021-02-19 19:52

    As mentioned in the comments, once you've installed the cowplot package you can load the plot_grid() function with the :: operator (see What are the double colons (::) in R?) and cowplot won't change any ggplot2 defaults.

    > plot_a <- ggplot(mtcars, aes(mpg, wt)) + geom_point()
    > plot_b <- ggplot(mtcars, aes(mpg, disp)) + geom_point()
    > plot_grid(plot_a, plot_b, labels = c("A", "B"))
    Error in plot_grid(plot_a, plot_b, labels = c("A", "B")) : 
      could not find function "plot_grid"
    
    > cowplot::plot_grid(plot_a, plot_b, labels = c("A", "B"))
    

    The issue comes when you load the entire cowplot package with library() or require().

提交回复
热议问题