r:为 xyplot {lattice} 中的每个点设置标签而不是为组

r: set labels for every point in xyplot {lattice} not for groups

我确信我的问题有一个简单的解决方案,但我找不到答案。我想 使用点阵为散点图 中的每个点值添加标签,而不是基本图。我发现 library(direct.label) 可以完成这项工作,很好的例子在这里:http://directlabels.r-forge.r-project.org/examples.html。 不过这里的标签显示的是组名,并不是每个点都显示value/name! 我想将我的数据按组(virginica、versicolor、setosa)分开,但也为图中的每个点(p.ex。Petal.Width)添加精确值。 请问,如何完成这个? 非常感谢!

library(lattice)
trellis.par.set(standard.theme(color=FALSE))
p <- xyplot(jitter(Sepal.Length)~jitter(Petal.Length),iris,groups=Species)
direct.label(p)

我所期望的(每个点生成的红色值):

你必须像这样在 trellis.focus 中使用 panel.text

p<-xyplot(jitter(Sepal.Length)~jitter(Petal.Length),iris,groups=Species)
p
trellis.focus("panel",1,1)
panel.text(x=p$panel.args[[1]]$x,y=p$panel.args[[1]]$y,labels = iris$Petal.Width, pos=3, cex=0.7, col="red")
trellis.unfocus()