简体   繁体   English

在 R 中绘制因子水平

[英]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".我正在使用鸢尾花数据,之前将物种因子从“setosa”、“versicolor”和“virginica”更改为“s”、“c”和“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?如果我对此进行编码: plot(iris$Sepal.Length, iris$Petal.Length, col = iris$Species)数据是可以更改为例如正方形的点: plot(iris$Sepal.Length, iris$Petal.Length, col = iris$Species, pch = 15)但是,我怎么能像这个图一样显示物种因子?

图

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:结果图:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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