2014-03-28 80 views
0

我正在使用以下代码来绘制2个变量的密度:车辆速度和坡度。但R会报错:ggplot2中的错误R studio中的geom_density

>p <- ggplot(data=final.data, aes(`Vehicle velocity`))+geom_density(aes(color=I('red'))) 
>p 
>Don't know how to automatically pick scale for object of type AsIs. Defaulting to continuous 
Error: Discrete value supplied to continuous scale 

是什么原因?提前致谢。

+0

是我在'color = I('red')'应该在那儿吗?否则它可能是数据格式 – JeremyS

回答

0

只有当它是映射到某个变量时,您才需要在aes调用中传递一些美感。查看区别

> ggplot(mtcars, aes(x = cyl)) + geom_density(color = "red") 
> ggplot(mtcars, aes(x = cyl)) + geom_density(aes(color = "red")) 

在这两个调用中,都不需要I()