5

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

4
  • 2
    If you give a reproducible example one could possibly help you Commented Jan 7, 2016 at 18:36
  • Possibly the same stackoverflow.com/questions/28846348/… Commented Jan 7, 2016 at 18:39
  • @PierreLafortune, not a a duplicate--that one's ggplot2, this is base-plotting Commented Jan 7, 2016 at 19:03
  • @PierreLafortune please note: you are referring ggplot package Commented Apr 27, 2016 at 7:05

1 Answer 1

14
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

Sign up to request clarification or add additional context in comments.

3 Comments

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 Good point / of course. I was just giving the example
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)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.