简体   繁体   中英

Plot factor levels in R

I'm using the iris data, previously changed the species factor from "setosa" "versicolor" and "virginica" to "s", "c" and "v". if I code this: plot(iris$Sepal.Length, iris$Petal.Length, col = iris$Species) The data are point which can change for example, to a square: plot(iris$Sepal.Length, iris$Petal.Length, col = iris$Species, pch = 15) but, how I could show the species factor like this graph?

图

Here we use the factor as an index to labels:

plot(iris$Sepal.Length, iris$Petal.Length, col = as.numeric(iris$Species)+1,
  pch = c("s", "c", "v")[as.numeric(iris$Species)])

Resulting plot:

用字母作为符号绘制的二维虹膜数据子集

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM