在晶格xyplot上添加标签 [英] Add labels on lattice xyplot
本文介绍了在晶格xyplot上添加标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用晶格创建了一个xyplot
I have created a xyplot with lattice
library(lattice)
X1=c(5, -2, 1, -3)
X2=X1^2
names=paste("dot", 1:4, sep="")
xyplot(X2~X1, data=data.frame(X1, X2), pch=20, cex=1:4)
现在,我想为每个点添加一个标签(文本).该信息位于
Now I want to add a label (text) for each dot. The info is in
names=paste("dot", 1:4, sep="")
我尝试了以下失败的尝试
I have tried with no success the following
panel.text(x=X2, y=X1, names)
或使用直接标签
library(directlabels)
p=xyplot(X2~X1,data=data.frame(X1, X2), pch=20, group=names, cex=1:4)
direct.label(p,smart.grid,FALSE)
但是我不太喜欢,因为我不得不使用group=names
分成几组,基本上每个点都在不同的组中?还有另一种方法吗?
but I don't like it much because I had to split into groups using group=names
, basically each dot is in a different group? Is there another way to do it?
推荐答案
您可以尝试定义新的面板函数:
You can try defining a new panel function:
xyplot(X2~X1, data=data.frame(X1, X2), pch=20, cex=1:4,
panel=function(x, y, ...) {
panel.xyplot(x, y, ...);
ltext(x=x, y=y, labels=names, pos=1, offset=1, cex=0.8)
})
这篇关于在晶格xyplot上添加标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文