Reputation: 49
I am trying to create a simple boxplot with all the labels. I have a dataset that says about the Number of customer Visits .It has two columns; Customer ID and AvgVists
custID AvgVisits
1 10
2 4
3 12
I want a simple boxplot that is horizontally oriented and displays the five summary points on the graph, with nice color and axes. I am able to find the heading, make it horizontally oriented, unable to report the summary numbers on the graph itself.
Upvotes: 0
Views: 3527
Reputation: 5274
@Henriks link seems to answer your question. This answer may also be helpful in terms of applying annotation to multiple boxplots on the same graph.
For completeness:
boxplot()
will calculate the no.s (same as fivenum()
) to plot, which you can verify by storing the result:
AvgVisits <- c(10,4,12)
b1 <- boxplot(AvgVisits)
b1$stats == fivenum(AvgVisits)
Here's a solution with ggplot2
which you may find appealing. Change the values of aes(x=)
to move the position up/down (as co-ordinates already flipped).
require(ggplot2)
q1 <- qplot(x=1, b1$stats, geom = "boxplot")
q1 +coord_flip() +
geom_text(aes(x=1.1,y=b1$stats,label=b1$stats)) +
opts(
axis.text.x=theme_blank(),
axis.text.y=theme_blank(),
axis.title.x=theme_blank(),
axis.title.y=theme_blank()
)
Giving:
Upvotes: 1
Reputation: 646
Use the text()
command, with the format text(location, "print this text", pos)
. pos
should be one of the following: 1=below, 2=left, 3=above, 4=right. If you need further assistance please include the code you have so far. More here: http://www.statmethods.net/advgraphs/axes.html
Upvotes: 0