[R] how do i creat multiple back to back histograms?

S Ellison S.Ellison at lgc.co.uk
Tue Jan 29 13:37:07 CET 2008


Is
?pyramid.plot
in the plotrix package of any help?

Plotting three of these on the same device is possible after

par(mfrow=c(1,3))


>>> Tom Willems <Tom.Willems at var.fgov.be> 29/01/2008 11:43:46 >>>
 dear R-ussers,
I would like to creeate a graph, i wich  my data is presented as
verticaly 
oriented histograms, wich give the frequency of the measured values, 
grouped per used measurement methode.
So the X axis should hold the grouping variable and the Y axis a
continuos 
variable. well not realy continouse, but it should show the values, 
representing the clase intervals.
small example to clarify this:
This one i can create: graph 1
only the positive results per test
5  |  ##                    |#                        |##  
    |  #                      |##                      |#
4  |  ###                  |####                  |
    |  ####                |######              |##
3  |  ###                  |#####                |####
    |  #####              |###                    |#####
2  |  ####                |                          |######
    |  ###                  |##                      |#####
1  |  #                      |#                        |##
    |_____________|_____________|_____________
0    test 1                test2                    test3
Tihs is what i want to create: graph 2
a back to back histogram plot of the pos/negative results, grouped per

test
5  |                      |##                  |#                     

|##  
    |                      |#                    |##                   

#|#
4  |                      |###                |####              ##|
    
| .....................|####..............|######
...........#|##......................
3  |                    #|###              #|#####               
|####
    |                  ##|#####        ##|###                ##|#####
2  
|............#####|####......####|..............######|######..............
    |                ###|###            ##|##                ###|#####
1  |                  ##|#                  #|#                ####|##
    |___________|__________#|____________#|_____________
0                    test 1                test2                   
test3
                   Neg. |  Pos.    Neg. |  Pos.         Neg. |  Pos.


I 'd like to creat the figure of graph 2, a back to back plot of the
pos/ 
and negative results of a test,
and this with the 3 tests in one graf.

I have been searching for examples,  the only trouble is that it is way
to 
complex.
(http://addictedtor.free.fr/graphiques/RGraphGallery.php?graph=109)
Here is one other example of a back to back plot (graph 2) .
(histbackback(fool)

After trying to understand wath happens in the complex example, i 
identified a part that does what i need.
It does creat the graph similar to what i want (graph 1).      "see
code 
below" 
Yet i do not understand it wel enough,so i can't creat the more complex

graph 2.
What can i do to understand this graph functions beter, without
spending 
to much time on them?

Kind regards,
Tom.

this is the code, wich i use to creat graph 1
# data for plot:

freqs <- data.frame(value= c( 
0.000,1.204,1.301,1.362,1.447,1.505,1.602,1.653,1.756,1.806,1.903,1.959,
     
2.053,2.107,2.204,2.258,2.354,2.408,2.505,2.559,2.656,2.709,2.806) ,
      tp1= c( 8,1,0,13,0,6,0,25,0,5,0,15,0,4,0,7,0,0,0,1,0,0,0)        
 ,
      tn1= c( 17,0,0,2,0,0,0,1,0,2,0,1,0,0,0,0,0,0,0,0,0,0,0)          
 ,
      tp2= c( 10,0,2,0,9,0,8,0,19,0,4,0,5,0,2,0,5,0,2,0,1,0,2)         
 ,
      tn2= c( 13,0,1,0,1,0,2,0,2,0,0,0,2,0,0,0,0,0,0,0,0,0,0)          
 ,
      tp3= c( 9,0,0,0,0,0,0,0,0,10,0,10,0,21,0,10,0,11,0,8,0,5,0)      
 ,
      tn3= c( 15,0,0,0,0,0,0,0,0,3,0,2,0,2,0,1,0,0,0,0,0,0,0)          
 )

 test<-c(1,2,3,4,5,6)
testname <-c('test1 p','test1 n','test2 p','test2 n','test3 p','test3
n')  
 


# parameters for plot 
 xlim = c(min(test),max(test))
 ylim = c(0,length(freqs$value))
 barscale = 0.2
 barcol = 8
 # plot 
 win.graph() 
 for (i in 1:length(freqs))
                  {
                 par(new = TRUE)
                 xmin <- -test[i] + xlim[1]
                 xmax <- xlim[2] - test[i]
                 ser <- freqs[, i+1]
                 ser <- ser/max(ser) * barscale
                 barplot(ser, horiz = TRUE, axes = FALSE, xlim =
c(xmin, 
xmax),
                         ylim = ylim, col = barcol, space = 0)
                    }
     axis(1,labels=testname,at=c(0,0.2,0.4,0.6,0.8,1))
     axis(2,labels=freqs$value ,at=c((0:22)/23) )

this is the code, wich i hoped would creat graph 2 but it doesn't work

for (i in 1:length(freqs))
                  {
                 par(new = TRUE)
                 xmin <- -test[i] + xlim[1]
                 xmax <- xlim[2] - test[i]
                 serx <- freqs[, i+1]
                 sery <- freqs[, i+2]
                 ser <- list((serx/sum(serx) *
barscale),(sery/sum(sery) * 
barscale))
                 histbackback(ser,axes=FALSE ,xlim = c(xmin, xmax),
ylim = 
ylim)
                    }



E-mail: tom.willems at var.fgov.be 









Disclaimer: click here
	[[alternative HTML version deleted]]

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help 
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html 
and provide commented, minimal, self-contained, reproducible code.

*******************************************************************
This email and any attachments are confidential. Any use...{{dropped:8}}



More information about the R-help mailing list