Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mtcars ggplot doesn't know how to deal with class numeric

Tags:

r

ggplot2

I am just trying to make a simple plot using mtcars and ggplot:

ggplot(data=mtcars, aes(x=mpg,y=hp))+geom_line(mpg,hp,col=cyl)

but I get the error:

ggplot doesnt know how to deal with class numeric

What is going on?

like image 422
Evan Avatar asked Dec 08 '25 05:12

Evan


1 Answers

My suggestion is to specify all aesthetics in one place and to coerce cyl to factor for colour coding as categorial variable.

ggplot(data=mtcars, aes(x=mpg, y=hp, colour=factor(cyl))) + geom_line()

will create enter image description here

like image 128
Uwe Avatar answered Dec 10 '25 18:12

Uwe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!