I need to include more species to the iris data set, the following plot only presents three species. How Can I make the code more flexible to include more than three species?
Asked
Active
Viewed 84 times
0
-
1The built in `iris` dataset only has three species. Are you trying to use different data? It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. Please don't post code or data as images since we can't copy/paste that into R for testing – MrFlick Mar 08 '22 at 18:58
-
Try pairs: `pairs(iris[-5], col = iris[[5]])` – G. Grothendieck Mar 08 '22 at 19:11
1 Answers
0
You are plotting the points on a single graph. You do not need a loop:
clrs <- rainbow(length(levels(iris$Species)))
plot(Petal.Width~Petal.Length, iris, main="My Graph", xlab="Petal Length", ylab="Petal Width", col=clrs[as.numeric(iris$Species)])
legend("topleft", legend=levels(iris$Species), pch=1, col=clrs)

dcarlson
- 10,936
- 2
- 15
- 18