## should work but doesn't! if (FALSE) { url0 <- "http://lalashan.mcmaster.ca/theobio/circumcision/index.php/" url1 <- "Special:GetProjectFile?project=Condom_awareness&make=false&filename=coefplot.RData" url2 <- "Special:GetProjectFile?project=Awareness_risk_behaviour&make=false&filename=coefplot.RData" download.file(paste0(url0,url1),dest="coefplot.RData") download.file(paste0(url0,url2),dest="coefplot2.RData") } ## DOWNLOAD THESE FILES to coefplot.RData and coefplot2.RData (doesn't matter which is which) ## the 'condom_awareness' one is big (58.2 MB), the 'awareness_risk_behaviour' one is small (2.9 KB) ## http://lalashan.mcmaster.ca/theobio/circumcision/index.php/Special:GetProjectFile?project=Awareness_risk_behaviour&make=false&filename=coefplot.RData ## http://lalashan.mcmaster.ca/theobio/circumcision/index.php/Special:GetProjectFile?project=Condom_awareness&make=false&filename=coefplot.RData L1 <- load("coefplot.RData") L2 <- load("coefplot2.RData") BiVars <- c("AIDSlookHealthyYes","knowsCondomProtectYes","knowsPersonHIVYes") newVarNames <- c("Knows PWHA may look healthy","Knows Condoms Protect from HIV","Knows Person with HIV/AIDS") library(ggplot2) library(proto) ## theme_set(theme_bw()) ## set b&w background y_dodge <- 0.1 source("geom-linerangeh.R") ## The palette with black: Palette <- c("#000000", "#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7") xlims <- c(-1.05,0.75) ## reorder countries by average coeftab5B <- coeftab5 coeftab5B$model <- with(coeftab5B,reorder(model,Estimate)) coeftab5B$model_dodge <- with(coeftab5B,as.numeric(model)+y_dodge*c(1,-1)[sex]) library(plyr) coeftab5B <- rename(coeftab5B,c(model="country",model_dodge="country_dodge")) countries <- levels(coeftab5B$country) g2 <- ggplot(coeftab5B,aes(x=Estimate, y=country_dodge, color=sex))+ geom_point()+ geom_linerangeh(aes(xmin=lwr,xmax=upr)) + scale_y_continuous(breaks=seq(length(countries)),labels=countries)+ geom_vline(xintercept=0, lty=2)+ labs(y="",x="Log-odds(knows person with HIV)") + scale_colour_manual(values=Palette)+ scale_x_continuous(limits=xlims) ## now transform coefplot information coeftab6 <- plot_cond_tab[BiVars,] coeftab6$var <- rownames(coeftab6) coeftab6$var <- newVarNames ## WARNING: FRAGILE, should match rather than depending on order! coeftab6 <- rename(coeftab6,c(`2.5%`="lwr",`97.5%`="upr")) g1 <- ggplot(coeftab6,aes(x=Estimate, y=var))+ geom_point()+ geom_linerangeh(aes(xmin=lwr,xmax=upr)) + geom_vline(xintercept=0, lty=2)+ labs(y="",x="Effect of knowledge on log-odds of infection")+ scale_x_continuous(limits=xlims) library(gridExtra) ## graph heights h1 <- 0.35; h2 <- 0.65 ## graph widths w1 <- 0.9; w2 <- 0.82 ## graph centers (x position) ctr1 <- 0.4; ctr2 <- 0.65 library(grid) vp1 <- viewport(x=unit(ctr1,"npc"),y=unit(1-h1/2,"npc"), width=unit(w1,"npc"),height=unit(h1,"npc")) vp2 <- viewport(x=unit(ctr2,"npc"),y=unit(h2/2,"npc"), width=unit(w2,"npc"),height=unit(h2,"npc")) pdf("comb_coefplot.pdf",width=5.25,height=3.75) grid.newpage() print(g2,vp=vp2) print(g1,vp=vp1) dev.off()