【问题标题】:Plot factor levels in R在 R 中绘制因子水平
【发布时间】:2023-04-01 20:21:01
【问题描述】:

我正在使用鸢尾花数据,之前将物种因子从“setosa”、“versicolor”和“virginica”更改为“s”、“c”和“v”。如果我这样编码: plot(iris$Sepal.Length, iris$Petal.Length, col = iris$Species) 数据是可以改变的点,例如,一个正方形: plot(iris$Sepal.Length, iris$Petal.Length, col = iris$Species, pch = 15) 但是,我怎么能像这样显示物种因素 图表?

【问题讨论】:

  • 试试pch = c("S", "C", "V")

标签: r plot


【解决方案1】:

这里我们使用因子作为标签的索引:

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

结果图:

【讨论】:

  • 完美,正是我需要的,谢谢!
猜你喜欢
  • 2023-03-27
  • 2017-11-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多