4

I have plotted box plot for my data using given command and trying to write text (p-value ) in it.

Using :

boxplot(data,ylab = prop_index[i])
text(1:2 - 0.4, data[,1]/2, paste("p-value=",p_val)) 

I applied "text" command but noting has appeared on image. Please tell me appropriate method to apply this command

Box plots are given

HubertL
  • 18,331
  • 3
  • 25
  • 45
user96368
  • 75
  • 1
  • 1
  • 7

1 Answers1

10
x1 <- rnorm(500)
y1 <- sample(c("a", "b", "c"), 500, replace=T)
boxplot(x1 ~ y1)
text(x= 1, y= 3, labels= "some text")
text(x= 2, y= 3, labels= "more \n text")
text(x= 3, y= 3, labels= "red text", col= "red")

enter image description here

Alex W
  • 4,619
  • 4
  • 28
  • 55
  • 3
    You can compress, the text additions into one line with `text(x= 1:3, y= 3, labels= c("some text","more \n text","red text"), col=c(NA,NA,"red"))`. – eipi10 Jan 07 '16 at 20:56
  • @eipi10 Good point / of course. I was just giving the example – Alex W Jan 07 '16 at 22:20
  • How do you do this if only using a single x value (i.e., no actual x value is assigned in boxplot)? In other words, if using `boxplot(y)` – theforestecologist May 04 '17 at 18:41