基于变量的色点(基 R)

我正在用基础 R 制作地图,我想根据数据集中的变量 (Lygodium_data$make.library.) 为点着色。 Lygodium_data$make.library。是一个数字变量(1 或 2)。这不起作用:

col.list <- c("black","red")
palette(col.list)
map("world",xlim=c(-105,-70),ylim=c(18,40),col="black")
map.axes(cex.axis=.375)
map("state",add=TRUE,lwd=1,col="black")
points(Lygodium_data$provided.longitude,Lygodium_data$provided.latitude,col = Lygodium_data$make.library.,cex = .5,pch = 16)

我收到错误: plot.xy(xy.coords(x,y),type = type,...) 中的错误: 无效的颜色名称 ''

任何帮助将不胜感激! 詹姆斯

tianshixincq 回答:基于变量的色点(基 R)

问题是在分配颜色时,base 要求分类变量是因子:

plot(iris$Sepal.Length,iris$Petal.Width,col = iris$Species)
# works fine

plot(iris$Sepal.Length,col = as.character(iris$Species))
# Error in plot.xy(xy,type,...) : invalid color name 'setosa'
本文链接:https://www.f2er.com/47103.html

大家都在问