错误:(从警告转换)忽略未知美学

问题描述:

有时,当我使用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-工作室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 

感谢

+1

'text' is not valid “geom_point”的美学。你想要'geom_text'还是'geom_label'?检查这些帮助页面。 –

+0

你有'选项(warn = 2)'在你的代码中的任何地方或可能通过工作区加载? – user20650

+0

@AndrewGustar我不这么认为:当我将'text'改为'geom_text'或'geom_label'时,我得到:'警告:忽略未知美学:geom_text'或'Warning:分别忽略未知美学:geom_label'。 –

广场ggplot下的审美映射而不是geom_point以避免警告:

## This produces an "unknown aesthetic" warning 
ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point(aes(text = cyl)) 

## This doesn't 
ggplot(mtcars, aes(x = wt, y = mpg, text = cyl)) + geom_point() 
+0

非常感谢。任何想法为什么有时警告和有时错误发布? –

+0

我的理解是,每一个geom都有一套它使用的美学。如果你提供一个它不知道该怎么处理,它会发出警告。由于'ggplot()'不知道它将与哪对象配对,因此它假定所有的审美映射都是有效的。 –

+0

就警告与错误而言,这是由问题评论中提到的getOption(“warn”)控制的。 'plotly'可能将'warn'选项升级为2,调用产生警告的'ggplot'部分,然后将'warn'解除升级回0.无需追踪源代码,就无法知道。 –