Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
427 views
in Technique[技术] by (71.8m points)

r - Error: could not find function "unit"

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...