[英]How to use `ggplot2`'s functions without loading the package?
When using ggplot2
, sometimes we need to use multiple functions in order to plot data:使用
ggplot2
,有时我们需要使用多个函数来绘制数据:
library("ggplot2")
p <- ggplot(mpg) +
geom_bar(aes(x = .data$drv)) +
coord_flip()
An alternative way to do this plot without loading the whole ggplot2
package would be:在不加载整个
ggplot2
包的情况下执行此绘图的另一种方法是:
p <-ggplot2::ggplot(ggplot2::mpg) +
ggplot2::geom_bar(ggplot2::aes(x = .data$drv)) +
ggplot2::coord_flip()
How can we do this plot without having to load the package throught library("ggplot2")
, or having to write ggplot2::
for every function?我们如何在不必通过
library("ggplot2")
加载包或不必为每个函数编写ggplot2::
情况下绘制此图?
withr::with_package
temporarily loads a package. withr::with_package
临时加载一个包。
p <- withr::with_package("ggplot2", {
ggplot(mpg) +
geom_bar(aes(x = drv)) +
coord_flip()
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.