0

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.

stripchart screenshot

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)

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.

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.

Any suggestions greatly appreciated!

Update: my ctrls object is more complex than I realized - maybe this is tripping me up:

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.......```
Joanne
  • 117
  • 7

1 Answers1

0

Here is one example using the built in data set for 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

example stripchart with text labels

Data

The lowest values of Ozone are:

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:

attr(ctrls$`Staining Green`, "threshold")
[1] 5

Plot

stripchart

Ben
  • 28,684
  • 5
  • 23
  • 45
  • Great, that's exactly what I'm looking for, thank you, but with this line ```with(subset(ctrls, `Staining Green` < 5), text(ctrls, 1.1, labels = `Staining Green`))``` I get the error ```object 'Staining Green' not found``` . The airquality is a dataframe whereas my ctrls object is a list (in fact 17 lists, with thresholds as attributes). I tried converting it with as.data.frame but then the stripchart fails in the first line. – Joanne Mar 23 '20 at 20:27
  • my update above is the output of ```str(ctrls)```, so Staining Green is one of 17 lists in the object, containing 504 numbers. – Joanne Mar 23 '20 at 22:35
  • ["Staining.Green" was my attempt to subset on a separate line, but that's not needed if I'm adapting the airquality code.] – Joanne Mar 23 '20 at 22:37
  • Brilliant, thank you! I will play with the positioning of labels, but that works :) – Joanne Mar 23 '20 at 22:49