Reputation: 4895
Box and Whisker graph displays the following information: max, min, mean, 75th percentile, 25th percentile. If I have these information, can I plot the corresponding B&W graph?
I have this data frame called TP.df:
pb1 ag1 pb2 ag2 pb3 ag3
Nb 498 498 85 85 68 68
Min 0 0 0 0 0 0
Max 1.72 461 2.641 260.8 0.3 144
Mean 0.06 19.2 0.15 35.35 0.02 9.11
75_p 0.06 20 0.08 33 0.02 8
25_p 0.01 10 0 14 0.01 4
file:
,pb1,ag1,pb2,ag2,pb3,ag3
Nb,498,498,85,85,68,68
Min,0,0,0,0,0,0
Max,1.72,461,2.641,260.8,0.3,144
Mean,0.06,19.2,0.15,35.35,0.02,9.11
75_p,0.06,20,0.08,33,0.02,8
25_p,0.01,10,0,14,0.01,4
How can I have the corresponding Box and Whisker graph:
pb1
, ag1
, pb2
, ag2
, pb3
, ag3
0
to max(TP.df[Max,])
Upvotes: 3
Views: 5594
Reputation: 21
Using manual boxplot with ggplot
, you can manipulate plot aesthetics and add other parameters:
ggplot()+geom_boxplot(aes(x=1, y = 2:5, lower = 3, upper = 4, middle = 3.5, ymin=2, ymax=5))
Upvotes: 1
Reputation: 801
Use bxp
to make a boxplot from a five-number summary.
Does this do the sort of thing you want?
testdata=data.frame(R1=c(0,5,3,2,4),R2=c(1,7,3,2.8,6))
o=c(1,5,3,4,2) # the rows in increasing order
bxp.data=list(stats=data.matrix(testdata[o,]),n=rep(1,ncol(testdata)))
# the n=... parameter doesn't affect the plot, but it still needs to be there
bxp(bxp.data)
You can use standard graphical parameters (see help(par)
) to label the axes and make it look pretty.
(Note: row numbers are off by one because the question was edited after I posted this answer. I'll leave the answer as is so that it matches the first two comments.)
Upvotes: 8
Reputation: 1471
that might be a solution:
#create a dummy boxplot that you can modify the data easily
z<- boxplot(1:10)
#look at the outbut an assign yout data to stats
z$stats<- your_data
#use bxp to plot, via add you can combine all three
bxp(z)
or use the bxp function from the beginning.. see also: http://r.789695.n4.nabble.com/Box-plot-with-5th-and-95th-percentiles-instead-of-1-5-IQR-problems-implementing-an-existing-solution-td3456123.html
ben
Upvotes: 1