错误:找不到功能“单位” [英] Error: could not find function "unit"

查看:144
本文介绍了错误:找不到功能“单位”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试修改主题设置时,此简单代码会给出以下错误:

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

do .call(theme,list(...)):找不到函数unit

R 给我这个错误的任何元素使用'单位'。任何其他不会调用'unit'的设置都可以正常工作。我正在运行R v.2.15.2(64位Windows)。



我在网上广泛搜索了关于这个问题,但什么都没发现。
我很感激这个问题的任何建议。

解决方案

这与密切相关,尽管不完全相同,不再支持ggplot2中的箭头(),它表示:

$ ggplot2中的箭头()不再支持b
$ b


[ grid [package]是由以前版本的 ggplot [2] (使
grid 函数对用户可见/可访问);现在它通过 NAMESPACE 导入引用
,所以如果$ b $需要显式加载 grid b要使用 grid 函数(或[查看他们的帮助页面])。

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

unit()是来自网格包,所以上面的答案(这是关于 arrow())适用。

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


While trying to modify theme settings this simple code gives the following error:

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"

R gives me this error for any element that uses 'unit'. Any other settings that do not call 'unit' work fine. I am running R v.2.15.2 (64-bit Windows).

I extensively searched online about this problem and found nothing. I appreciate any suggestions to the problem.

解决方案

This is closely related to, although not exactly identical to, arrow() in ggplot2 no longer supported , which says:

[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).

"explicitly load" here means library("grid") or require("grid") (grid is a base package, so doesn't need to be installed separately).

unit() is a function from the grid package, so the answer above (which was about arrow()) applies.

Alternatively you can specify grid::unit(...) or grid::arrow(...) without explicitly loading the entire package.

这篇关于错误:找不到功能“单位”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆