如何使用mtcars数据集中的隐藏列标记R中的散点图?

时间:2019-07-26 18:14:10

标签: r

我使用R中的mtcars数据集绘制了散点图,x轴上为mpg,y轴上为wt。我现在正尝试根据第一列(汽车的型号)来标记数据点,但是由于此列没有任何名称,因此我无法标记出地块

attach(mtcars)
plot(mpg,wt,
     xlab = "Miles per Gallon",
     ylab = "Weight of car (in metric tonnes)",
     col = "blue" , pch = 19)    

text(mpg,wt, labels = "?" , cex = 0.7)

1 个答案:

答案 0 :(得分:0)

使用rownames(mtcars)

fo <- wt ~ mpg
plot(fo, mtcars,
     xlab = "Miles per Gallon",
     ylab = "Weight of car (in metric tonnes)",
     col = "blue" , pch = 19)    

text(fo, mtcars, labels = rownames(mtcars) , cex = 0.7)

screenshot