如何在'抖动'散点图中标记点

时间:2016-11-30 19:58:13

标签: r scatter-plot

我试图在散点图中标记我的所有点,其中包含与变量关联的国家/地区的名称,但所有标签都向下移动。这不是正确的方法:

plot(jitter(data$variable1,2), jitter(data$variable2,2), main = "Bivariate relationship between variable1 and variable2", xlim = c(0,100), ylim = c(0,100), xlab = "Variable 1", ylab = "Variable 2", col = "red", pch = 15)

text(jitter(data$variable1,2), jitter(data$variable2,2), labels = data$Country)

This is what the scatterplot looks like without labels 我们的数据集是这样的:

Country   Variable1  Variable2 
France        2          2
Turkey        1          3 

1 个答案:

答案 0 :(得分:0)

这会回答你的问题吗?

Country=c("France", "Turkey")
Variable1 = c(2, 1)
Variable2 = c(2, 3)
df = data.frame(Country, Variable1, Variable2)
x1=jitter(Variable1, 2);x2=jitter(Variable2, 2)
plot(x1, x2, xlim = c(min(x1)-1, max(x1)+1), ylim=c(min(x2)-1, max(x2)+1))
text(x1,x2, labels=df$Country, cex=.7, pos=3)

enter image description here