[R] histbackback function

Jim Lemon jim at bitwrit.com.au
Tue Dec 8 11:14:16 CET 2009


>
> Hi,
> I'm trying to recreate a sensitivity-specificity graph using the
> histbackback function.  The only problem is that these graphs are typically
> drawn with vertical rather than horizontal bar plots (and the histbackback
> function only seems to work with horiz=TRUE argument, using "horiz=FALSE"
> doesn't work).  Does anyone know if:
> 1) there's a different graphing function that would accomplish this graph?
> 2) if there isn't, is there a way to rotate the graph 90 degrees clockwise?
> 3) with the histbackback function, is there a way to display percent instead
> of proportion on the x-axis?
> 4) with the histbackback function, is there a way to set the width of the
> bins (ie I want bars in increments of 10 or 20 instead of 50 , "bin=10"
> didn't work)
> 5) with the histbackback function, is there a way to display the y-axis
> values where the two histograms are back to back, rather than on the y-axis?
>
> Below, I've pasted the graph that I'm trying to recreate, as well as the
> code and graph from my current (unsuccessful) attempt.
>
> options(digits=1)
> require(Hmisc)
> out<- histbackback(split(data8$TB144, data8$PRES), probability=TRUE,
> main="Back to Back Histogram", ylab="TB144 1min rates")
> barplot(-out$left, col="ivory2", horiz=TRUE, space=0, add=TRUE, axes=FALSE)
> barplot(out$right, col="ivory4", horiz=TRUE, space=0, add=TRUE, axes=FALSE)
> grid(nx=NULL, ny = NULL, col = "lightgray", lty = "dotted", lwd =
> par("lwd"), equilogs = TRUE)
>
> http://n4.nabble.com/file/n954888/sens-spec%2Bgraph.jpg
>
> http://n4.nabble.com/file/n954888/back-to-back%2Bhistogram%2B2.jpg
>
>
>    
Hi Katie,
You can get most of what you want with "barplot":

sens<-c(2,4,6,5,7,6,9,10,12)
spec<-c(7,4,5,3,1,0,0,1,0)
xpos<-barplot(sens,ylim=c(-15,15),col=NA,axes=FALSE)
barplot(-spec,add=TRUE)
axis(2,at=c(-10,0,10),labels=c(-10,0,10))
par(xpd=TRUE)
text(xpos,sens+1,sens)
text(xpos,-(spec+1),spec)
par(xpd=FALSE)

except that the "axes" argument doesn't seem to work. I can't read your 
example, but this should give you the idea.

Jim




More information about the R-help mailing list