forest plot three shapes in R -


i using "pimp forest plot" make nice graphs. http://www.r-bloggers.com/pimping-your-forest-plot/

the tutorial explains how make nice forest plot, combing data 2 countries have @ subgroup effects. each country has own distinctive shape on graph eg sweden diamond... subgroup effects in countries easy pick out.

i'm having problem when trying merge 3 dfs (for 3 countries) though. instead of retaining separate shapes each country in each subgroup (see graph when combining 2 countries), when put 3 countries shapes gender circular, shapes age square , on. instead should there circle, diamond , square represent effects of gender/age in each country.

does know i'm doing wrong here? i've been retracing steps , adding 1 df @ time can @ least try see i'm doing wrong: it's not coming me.

i've copied dfs "pimp forest plot" here: credit these graphs max gordon. i've made fake third df called "finland" sake of example here.

sweden1              coef       lower       upper     males vs female          0.04088551  0.03483956  0.04693145     85 vs 65 years          -0.05515741 -0.06508088 -0.04523394     charlsons medium vs low -0.03833060 -0.04727946 -0.02938173  denmark1                                coef        lower       upper males vs female          0.03462842  0.003494374 0.065762462 85 vs 65 years          -0.03682791 -0.083367305 0.009711488 charlsons medium vs low -0.04335537 -0.090336663 0.003625929   finland1                           coef  lower  upper males vs female          0.061  0.043  0.087 85 vs 65 years          -0.080 -0.120 -0.020 charlsons medium vs low -0.050 -0.075 -0.025 

to make forest plot 2 countries: use max gordon's code referenced website:

library(forestplot) forestplot(mean=cbind(sweden1[,"coef"], denmark1[,"coef"]),              lower=cbind(sweden1[,"lower"], denmark1[,"lower"]),              upper=cbind(sweden1[,"upper"], denmark1[,"upper"]),              labeltext=rownames(sweden),             legend=c("sweden", "denmark"),              legend.pos=list(x=0.8,y=.4),             legend.gp = gpar(col="#aaaaaa"),              legend.r=unit(.1, "snpc"),             clip=c(-.2, .2),              xticks=c(-.2, -.1, .0, .1, .2),             boxsize=0.3,             col=fpcolors(box=c("blue", "darkred")),             # set different functions             confintnormalfn=c("fpdrawdiamondci", "fpdrawcircleci"),             xlab="eq-5d index",             new_page=true) 

i use code add in finland, see how shapes not stay true groups.

forestplot(mean=cbind(sweden1[,"coef"], denmark1[,"coef"],finland1[,"coef"]),              lower=cbind(sweden1[,"lower"], denmark1[,"lower"],finland1[,"lower"]),              upper=cbind(sweden1[,"upper"], denmark1[,"upper"],finland1[,"upper"]),              labeltext=rownames(sweden1),             legend=c("sweden", "denmark", "finland1"),              # added clip argument of              # danish ci way out therer             #clip=c(-.2, .2),              # getting ticks auto-generate              # nightmare - better              # specify them on own            # xticks=c(-.2, -.1, .0, .1, .2),             boxsize=0.3,             col=fpcolors(box=c("blue", "darkred", "green")),            confintnormalfn=c("fpdrawcircleci",  "fpdrawnormalci","fpdrawdiamondci"),             xlab="eq-5d index",             new_page=true) 

thanks in advance.

edit

sweden1 <- structure(c(0.0408855062954068, -0.0551574080806885, -0.0383305964199184,  0.0348395599810297, -0.0650808763059716, -0.0472794647337126,  0.046931452609784, -0.0452339398554054, -0.0293817281061242), .dim = c(3l,  3l), .dimnames = list(c("males vs female", "85 vs 65 years",  "charlsons medium vs low"), c("coef", "lower", "upper")))  denmark1 <- structure(c(0.0346284183072541, -0.0368279085760325, -0.0433553672510346,  0.00349437418972517, -0.0833673052667752, -0.0903366633240568,  0.065762462424783, 0.00971148811471034, 0.00362592882198759), .dim = c(3l,  3l), .dimnames = list(c("males vs female", "85 vs 65 years",  "charlsons medium vs low"), c("coef", "lower", "upper")))  finland1 <- structure(c(0.061, -0.08, -0.05, 0.043, -0.12, -0.075, 0.087,  -0.02, -0.025), .dim = c(3l, 3l), .dimnames = list(c("males vs female",  "85 vs 65 years", "charlsons medium vs low"), c("coef", "lower",  "upper"))) 

it hard deduce intention of different drawing functions in square structure , therefore need supply function square matrix, in case 3x3 matrix. not sure wisest design choice part, rather simple fix:

sweden1 <-    structure(c(0.0408855062954068, -0.0551574080806885, -0.0383305964199184,                0.0348395599810297, -0.0650808763059716, -0.0472794647337126,                0.046931452609784, -0.0452339398554054, -0.0293817281061242),              .dim = c(3l, 3l),              .dimnames = list(c("males vs female", "85 vs 65 years", "charlsons medium vs low"),                              c("coef", "lower", "upper")))  denmark1 <- structure(c(0.0346284183072541, -0.0368279085760325, -0.0433553672510346,                          0.00349437418972517, -0.0833673052667752, -0.0903366633240568,                          0.065762462424783, 0.00971148811471034, 0.00362592882198759),                        .dim = c(3l, 3l),                        .dimnames = list(c("males vs female", "85 vs 65 years", "charlsons medium vs low"),                                        c("coef", "lower", "upper")))  finland1 <- structure(c(0.061, -0.08, -0.05,                          0.043, -0.12, -0.075,                          0.087, -0.02, -0.025),                       .dim = c(3l, 3l),                        .dimnames = list(c("males vs female", "85 vs 65 years", "charlsons medium vs low"),                                        c("coef", "lower", "upper")))  forestplot(mean=cbind(sweden1[,"coef"], denmark1[,"coef"],finland1[,"coef"]),             lower=cbind(sweden1[,"lower"], denmark1[,"lower"],finland1[,"lower"]),             upper=cbind(sweden1[,"upper"], denmark1[,"upper"],finland1[,"upper"]),             labeltext=rownames(sweden1),            legend=c("sweden", "denmark", "finland1"),             boxsize=0.1,            col=fpcolors(box=c("kblue", "darkred", "darkgreen")),            fn.ci_norm=matrix(c("fpdrawcircleci",  "fpdrawnormalci","fpdrawdiamondci"),                               nrow = 3, ncol=3, byrow=t),            xlab="eq-5d index",            new_page=true) 

produces graph:

enter image description here


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -