【发布时间】:2018-03-18 06:08:55
【问题描述】:
有时当我使用ggplot2 时,会出现以下错误:
> dframe <- data.frame(a=letters, b=LETTERS, x=runif(26), y=runif(26))
> p <- ggplot(dframe, aes(x,y)) + geom_point(aes(text=sprintf("letter: %s<br>LETTER: %s", a, b)))
Error: (converted from warning) Ignoring unknown aesthetics: text
然后我重新启动 R-Studio(当您的工作未完成时,这非常令人生畏)并且一切正常(直到问题再次发生):
> dframe <- data.frame(a=letters, b=LETTERS, x=runif(26), y=runif(26))
> p <- ggplot(dframe, aes(x,y)) + geom_point(aes(text=sprintf("letter: %s<br>LETTER: %s", a, b)))
Warning: Ignoring unknown aesthetics: text
> ggplotly(p)
We recommend that you use the dev version of ggplot2 with `ggplotly()`
Install it with: `devtools::install_github('hadley/ggplot2')`
有什么问题?我正在使用 Windows 10、R-studio 1.0.153 和以下 R 版本:
> R.version
_
platform x86_64-w64-mingw32
arch x86_64
os mingw32
system x86_64, mingw32
status
major 3
minor 4.2
year 2017
month 09
day 28
svn rev 73368
language R
version.string R version 3.4.2 (2017-09-28)
nickname Short Summer
对应的包有以下版本:
ggplot2 2.2.1
plotly 4.7.1
谢谢
【问题讨论】:
-
text不是geom_point的有效美学。你想要geom_text还是geom_label?检查这些帮助页面。 -
您的代码中是否有
options(warn=2)或者可能通过工作区加载? -
@AndrewGustar 我不这么认为:当我将
text更改为geom_text或geom_label时,我分别得到了:Warning: Ignoring unknown aesthetics: geom_text或Warning: Ignoring unknown aesthetics: geom_label。 -
@user20650 不,我没有在我的代码中的任何地方输入
options(warn=2)。options()$warn返回[1] 0 -
好吧,这是一个猜测,但它确实重现了将警告升级为错误的行为:例如:
options(warn=0) ; ggplot(dframe, aes(x,y)) + geom_point(aes(text=sprintf("letter: %s<br>LETTER: %s", a, b))) ; options(warn=2) ; ggplot(dframe, aes(x,y)) + geom_point(aes(text=sprintf("letter: %s<br>LETTER: %s", a, b)))