1
I’m working with the data set starwars
, package dplyr
. My goal is to create a chart with this data, where the independent variable is the height of the characters, and the dependent is their body mass:
library(dplyr)
starwars
plot(starwars$mass ~ starwars$height, ylim = c(0, 200))
The next step would be to differentiate by color the species of the sample units, and this is where an error message appears:
plot(starwars$mass ~ starwars$height, ylim = c(0, 200), col = starwars$species)
Error in plot.xy(xy, type, ...): invalid color name 'Human'
The error seems to be with the 'Human' class, but what may be happening?
Thank you very much, I did so and it worked! I was only in doubt about the legend, because when I inserted the commands R read normally, but it did not appear on the graph:
plot(starwars$mass ~ starwars$height, ylim = c(0, 200),
col = as.factor(starwars$species), legend("bottomleft", legend = as.factor(starwars$species)))
– Arthur Filipe