gpt4 book ai didi

r - 错误: could not find function "unit"

转载 作者:行者123 更新时间:2023-12-03 05:14:40 24 4
gpt4 key购买 nike

在尝试修改主题设置时,这个简单的代码会出现以下错误:

library(ggplot2)
theme_nogrid <- theme_set(theme_update(
plot.margin=unit(c(.25, .25, .25, .25), "in"),))

Error in do.call(theme, list(...)) : could not find function "unit"
对于任何使用“unit”的元素,

R 都会出现此错误。任何其他不调用“单位”的设置都可以正常工作。我正在运行 R v.2.15.2(64 位 Windows)。

我在网上广泛搜索了这个问题,但一无所获。我很感激对这个问题的任何建议。

最佳答案

这与 arrow() in ggplot2 no longer supported 密切相关,但并不完全相同。 ,其中表示:

[the] grid [package] was loaded automatically by previous versions of ggplot[2] (making grid functions visible/accessible to the user); now it's referred to via NAMESPACE imports instead, so you need to explicitly load grid if you want to use grid functions (or [to] look at their help pages).

“显式加载”在这里意味着library("grid")require("grid")(grid是一个基础包,所以不需要单独安装)。

unit()grid 包中的函数,因此上面的答案(关于 arrow())适用。

或者,您可以指定 grid::unit(...)grid::arrow(...) 而无需显式加载整个包。

关于r - 错误: could not find function "unit",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14885150/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com