R绘图将点颜色分配给行名称

时间:2022-09-16 19:16:36

Here is my data frame:

这是我的数据框:

      Z            melting.point
AIN  -1.7596934    -0.3184053
AIP  -1.3968700     0.2290334
AIAs -0.5805174     1.8950577

The first columns replaces with the chemical names of the observations the initial default in R:

第一列替换了R中初始默认值的观察结果的化学名称:

     compounds      Z                 melting.point
1       AIN        -1.7596934        -0.3184053
2       AIP        -1.3968700         0.2290334
3      AIAs        -0.5805174         1.8950577

So, based on the first data frame, I'd like to run a command such as:

所以,基于第一个数据框,我想运行一个命令,如:

plot(melting.point ~ Z, col = rownames(dat), data = dat)

but I get an error message:

但是我收到一条错误消息:

Error in eval(expr, envir, enclos) : object 'compounds' not found

Is there a way of coloring the points based on the row names of a data frame?

有没有一种方法可以根据数据框的行名对点进行着色?

1 个解决方案

#1


I cant reproduce your error but rownames(dat) is not a suitable colorname. So, try it with a factor or a numeric vector.

我无法重现您的错误,但rownames(dat)不是合适的颜色名称。因此,尝试使用因子或数字向量。

plot(melting.point ~ Z, col = as.factor(rownames(dat)),data = dat)
plot(melting.point ~ Z, col = 1:nrow(dat),data = dat)

#1


I cant reproduce your error but rownames(dat) is not a suitable colorname. So, try it with a factor or a numeric vector.

我无法重现您的错误,但rownames(dat)不是合适的颜色名称。因此,尝试使用因子或数字向量。

plot(melting.point ~ Z, col = as.factor(rownames(dat)),data = dat)
plot(melting.point ~ Z, col = 1:nrow(dat),data = dat)