Error: (converted from warning) Ignoring unknown a

2019-08-18 14:35发布

问题:

Sometimes when I use ggplot2 I get following error:

> 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

Then I restart R-Studio (which is pretty daunting when you have your work unfinished) and everything works fine (until the problem happens again):

> 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')`

What is the problem? I'm using Windows 10, R-studio 1.0.153, and following R version:

> 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           

Corresponding packages are following version:

ggplot2 2.2.1
plotly  4.7.1

Thanks

回答1:

Place the aesthetic mapping under ggplot instead of geom_point to avoid the warning:

## 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()


标签: r ggplot2