[英]add data labels to stripchart
I have made a stripchart with a threshold marked in red.我制作了一个带红色标记的阈值的带状图。 I would like to label the point that falls to the left of the threshold, but can't seem to get the 'text' function working at all.我想标记落在阈值左侧的点,但似乎根本无法使“文本”功能正常工作。
Here is the stripchart code: stripchart(ctrls$`Staining Green`, method="jitter", pch=4, xlab='Staining Green', cex.lab=2) abline(v=5,col=2,lty=3)
这是带状图代码: stripchart(ctrls$`Staining Green`, method="jitter", pch=4, xlab='Staining Green', cex.lab=2) abline(v=5,col=2,lty=3)
I first tried to filter only those samples below the threshold: Staining.Green <- filter(QCcontrols, Staining.Green < 5)
then adding the text with text(Staining.Green$`Staining Green` + 0.1, 1.1, labels = Staining.Green$Sample_Name, cex = 2)
This didn't add any text to the chart.我首先尝试仅过滤低于阈值的那些样本: Staining.Green <- filter(QCcontrols, Staining.Green < 5)
然后添加带有text(Staining.Green$`Staining Green` + 0.1, 1.1, labels = Staining.Green$Sample_Name, cex = 2)
这没有向图表添加任何文本。
Then I tried labeling all the points, in case I was making it too complicated, with variations on: text(ctrls$`Staining Green` + 0.1, 1.1, labels = ctrls$Sample_Name)
Again, no text added, and no error message.然后我尝试标记所有的点,以防万一我把它弄得太复杂了,有变化: text(ctrls$`Staining Green` + 0.1, 1.1, labels = ctrls$Sample_Name)
同样,没有添加文本,也没有错误消息.
Any suggestions greatly appreciated!任何建议非常感谢!
Update: my ctrls object is more complex than I realized - maybe this is tripping me up:更新:我的 ctrls 对象比我意识到的要复杂 - 也许这让我感到困惑:
List of 17
$ Restoration : num [1:504] 0.0799 0.089 0.1015 0.1096 0.1092 ...
..- attr(*, "threshold")= num 0
$ Staining Green : num [1:504] 25.1 23.5 21.1 19.7 22.3 ...
..- attr(*, "threshold")= num 5
$ Staining Red : num [1:504] 39.8 40.9 36.9 33.2 33.2 ...
..- attr(*, "threshold")= num 5.......```
Here is one example using the built in data set for airquality
:以下是使用内置airquality
数据集的一个示例:
stripchart(airquality$Ozone,
main="Mean ozone in parts per billion at Roosevelt Island",
xlab="Parts Per Billion",
ylab="Ozone",
method="jitter",
col="orange",
pch=4
)
abline(v = 5, col = 2, lty = 3)
with(subset(airquality, Ozone < 5), text(Ozone, 1.1, labels = Ozone))
Plot阴谋
Data数据
The lowest values of Ozone
are: Ozone
的最低值是:
head(sort(airquality$Ozone), 5)
[1] 1 4 6 7 7
Edit :编辑:
Here's a quick demo with a list with a similar structure:这是一个带有类似结构的列表的快速演示:
vec1 <- c(0.0799, 0.089, 0.1015, 0.1096, 0.1092)
attr(vec1, 'threshold') <- 4
vec2 <- c(25.1, 3, 21.1, 19.7, 22.3)
attr(vec2, 'threshold') <- 5
ctrls <- list(Restoration = vec1, `Staining Green` = vec2)
stripchart(ctrls$`Staining Green`,
method="jitter",
pch=4,
xlab='Staining Green',
cex.lab=2
)
abline(v=5,col=2,lty=3)
text(ctrls$`Staining Green`[ctrls$`Staining Green` < 5], 1.1, labels = ctrls$`Staining Green`[ctrls$`Staining Green` < 5])
Note: Instead of explicitly including 5 for threshold you can substitute the threshold
from your list attribute:注意:您可以替换列表属性中的threshold
,而不是明确包含 5 作为阈threshold
:
attr(ctrls$`Staining Green`, "threshold")
[1] 5
Plot阴谋
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.