[R] Propensity Score Graph XXXX
Jim Lemon
drjimlemon at gmail.com
Wed Jun 3 00:51:21 CEST 2015
Hi Dan,
With a bit of arm-twisting, you can get pretty close with pyramid.plot
(plotrix).
lx<-c(0,0,0,0,0,0,0,0,0,0,0,0,0,20,30,55,60,60,70,80,100,90)
rx<-c(90,95,95,80,70,65,75,54,52,50,40,20,0,0,0,0,0,0,0,0,0,0)
library(plotrix)
x11(width=10)
pyramid.plot(lx,rx,labels=rep("",22),gap=0,top.labels=rep("",3),
laxlab=seq(0,100,by=10),raxlab=seq(0,100,by=10),
unit="",lxcol=rep("gray",22),rxcol=rep("gray",22),ppmar=c(4,6,2,6))
axis(2,at=c(1,11,22),labels=c(0,0.5,1),pos=-110)
mtext("Number of observed subjects",side=1,line=2)
mtext("Estimated probability of exposure",side=2,line=4.5)
par(xpd=TRUE)
arrows(c(-100,100),c(0,0),c(-110,110),c(0,0))
text(-85,17,"Actually exposed")
text(98,7,"Actually unexposed")
par(xpd=FALSE)
Jim
On Wed, Jun 3, 2015 at 7:01 AM, Boris Steipe <boris.steipe at utoronto.ca> wrote:
> Easy to write - here's a quick piece of code (without bells and whistles though...)
>
>
>
> dat1 <- rnorm(1000)
> dat2 <- rgamma(3000, shape=3)
>
> biHist <- function(d1, d2) {
> col1 <- "#FFCCBB"
> col2 <- "#BBCCFF"
> hAll <- hist(c(d1, d2))
> hD1 <- hist(d1, breaks=hAll$breaks)
> hD2 <- hist(d2, breaks=hAll$breaks)
> plot(NULL,
> xlim = c(-1.05 * max(hD1$counts), 1.05 * max(hD2$counts)),
> ylim = c(min(hAll$breaks), max(hAll$breaks)),
> xlab = "frequencies",
> ylab = "values",
> xaxt = "n")
> axis(side = 1,
> lwd = 0,
> lwd.ticks = 1,
> at = axTicks(1),
> labels = abs(axTicks(1)))
> abline(v = 0)
> rect(-hD1$counts,
> hAll$breaks[-length(hAll$breaks)],
> 0,
> hAll$breaks[-1],
> col=col1)
> rect(0,
> hAll$breaks[-length(hAll$breaks)],
> hD2$counts,
> hAll$breaks[-1],
> col=col2)
> }
>
> biHist(dat1, dat2)
>
>
>
> Let me know in case this needs modifications that you can't easily make yourself
> :-)
>
>
> B.
>
>
>
>
>
>
> On Jun 2, 2015, at 4:43 PM, David Winsemius <dwinsemius at comcast.net> wrote:
>
>>
>> On Jun 2, 2015, at 11:13 AM, Dan Abner wrote:
>>
>>> Hi all,
>>>
>>> Does anyone know how to create a graph of propensity scores like the
>>> one on the left in the attachment? I can easily generate the one on
>>> the right: How does one force the respective histograms to share the
>>> same rotated x-axis? Is it possible to set the horizontal white space
>>> between these to graphs to 0 so that there is only the single line
>>> running down the middle of the graph?
>>>
>>
>> I think you will find that "pyramid" plots of this sort are in some packages and that similar requests (to get rid of the middle space) have been made in the past. Pyramid plots are often used by demographers to compare and display age distributions of both genders. Why not see if that work can be found with a search engine. I use this MarkMail link on my browser to search the Archive
>>
>> http://markmail.org/search/?q=list%3Aorg.r-project.r-help
>>
>> ....(but you could also direct the Google Advanced Search function to the real Archives if you wanted:
>>
>> https://stat.ethz.ch/pipermail/r-help/
>>
>>
>>> Thanks,
>>>
>>> Dan
>>> <graphs.pdf>______________________________________________
>>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> 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.
>>
>> David Winsemius
>> Alameda, CA, USA
>>
>> ______________________________________________
>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> 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.
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
More information about the R-help
mailing list