R-为什么我无法在R中的绘图中使用text()函数?

问题描述 投票:0回答:1

[我从IMF建立的有关各国人口动态的数据中创建了一个data.frame(《世界经济展望》:]

   Country Afghanistan Albania Algeria Angola Antigua.and.Barbuda    Argentina Armenia Aruba Australia  
1    1980        <NA>   2.672  18.666  8.910               0.068   27.950    <NA>  <NA>    14.802      
2    1981        <NA>   2.726  19.246  9.151               0.068   28.450    <NA>  <NA>    15.039

然后我为阿根廷创建了一个地块:

plot(mydata$Country, mydata$Argentina)

并尝试为数据标签添加文本:

text(x = mydata$Country,y = mydata$Argentina,labels = mydata$Argentina,cex=0.2)

但是我什么也没看到:(

相反,我可以在mtcars中很容易做到:

plot(a$mpg, a$hp)
text(a$mpg, a$hp, a$hp)

我的示例出了什么问题?

r text label
1个回答
0
投票
[Aziz在他的评论中似乎是正确的。如果您运行:

## This is the data mydata <- data.frame(Country = 1980:1981, Argentina= c(27.95, 28.54)) ## This is the plot plot(mydata$Country, mydata$Argentina) ## This writes text in the plot text(x = mydata$Country,y = mydata$Argentina,labels = mydata$Argentina,cex=1)

您确实会在情节中看到与阿根廷相对应的数字以文字形式显示。     
© www.soinside.com 2019 - 2024. All rights reserved.