簡體   English   中英

r:為xyplot {lattice}中的每個點設置標簽,而不是為組設置標簽

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

我敢肯定我的問題有一個簡單的解決方案,但我找不到答案。 我想使用晶格而不是基本圖在散點圖中為每個點值添加標簽 我發現該library(direct.label)可以完成此工作,這里的示例很好: http : library(direct.label) 但是,這里的標簽顯示的是組的名稱,而不是每個點的值/名稱! 我想將數據按組(弗吉尼亞州,雜色,setosa)分開,但還要在圖中為每個點(例如花瓣寬度)添加確切的值。 拜托,如何完成呢? 非常感謝 !

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

我所期望的(每個點生成的紅色值):

在此處輸入圖片說明

你必須使用panel.texttrellis.focus是這樣的:

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()

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM