I am trying to make a survival plot (step function), with confidence intervals. I was able to do this using three geom_step calls. However, I would like the plot to look 'nicer' using geom_ribbon. Any suggestions? Here is example code.
est1 <- NULL
est1$t <- c(0.003283737,0.004230144,0.004784251,0.006796506,0.017014431,0.018175468,0.022076831,0.024729164,0.037227658,0.038766478,0.039162908,0.041195399,0.043019651,0.046722404,
0.051616966,0.055032852,0.055918036,0.069959089,0.076636189,0.077441589,0.082228315,0.082702568,0.083122233,0.106367283,0.115066197,0.125658441,0.138187258,0.144906708,
0.15516234,0.193250853,0.195686997,0.219126171,0.221717509,0.227252041,0.235954549,0.252570273,0.253118261,0.266060572,0.27695104,0.282782354,0.306754979,0.324947741,
0.333478615,0.338614841,0.340449456,0.345983713,0.351361435,0.35366061,0.356729225,0.35759008,0.368935101,0.376310312,0.388861909,0.389338523,0.389724514,0.39308606,
0.393962892,0.39458893,0.395113668,0.406517405,0.419489873,0.419647944,0.427932732,0.429010032,0.436226965,0.447974342,0.45002121,0.450584569,0.455356801,0.46373873,
0.464306005,0.468366403,0.472845783,0.474036238,0.483850263,0.486225583,0.502337307,0.504825319,0.521771953,0.524550023,0.525444921,0.542867794,0.549514181,0.549984628,
0.577355239,0.586273623,0.589188332,0.62315272,0.635906942,0.662302356,0.663420801,0.664747602,0.714458874,0.724201796,0.750435915,0.780806018,0.813868952,0.815190783,
0.832776005,0.835423434,0.836300429,0.860601518,0.863246586,0.873005453,0.875679188,0.914858632,0.923980351,0.942925332,0.968740543,0.973588696,0.985521733,1.001920655,
1.011241937,1.03249434,1.115972407,1.136439005,1.186783699,1.22681115,1.231311762,1.236583951,1.5)
est1$SURV11 <- c(0.9909211,0.9818422,0.9818422,0.9818422,0.9818422,0.9727633,0.9727633,0.9636844,0.9636844,0.9546055,0.9546055,0.9546055,0.9546055,0.9455266,0.9364477,0.9364477,0.9364477,
0.9364477,0.9272668,0.9272668,0.9272668,0.9272668,0.9272668,0.9272668,0.917758,0.917758,0.8987405,0.8987405,0.8987405,0.8987405,0.8892317,0.8892317,0.8892317,0.8892317,
0.8892317,0.8892317,0.8892317,0.869203,0.869203,0.869203,0.8589105,0.8380314,0.8380314,0.8380314,0.8380314,0.8380314,0.8272803,0.8165291,0.8165291,0.805778,0.805778,0.805778,
0.79468,0.79468,0.79468,0.783582,0.783582,0.783582,0.783582,0.772484,0.772484,0.761386,0.7502881,0.7391901,0.7391901,0.7391901,0.7391901,0.7391901,0.7278866,0.7278866,0.7278866,
0.7278866,0.7052796,0.7052796,0.7052796,0.6826726,0.6713691,0.6600656,0.6600656,0.6600656,0.6487622,0.6372018,0.6372018,0.6256414,0.6256414,0.6256414,0.6013645,0.5764489,0.5764489,
0.5764489,0.5764489,0.563991,0.5511668,0.5375151,0.5375151,0.5238635,0.5097243,0.5097243,0.5097243,0.5097243,0.4950414,0.4950414,0.4950414,0.4950414,0.4656754,0.4656754,0.4656754,
0.4349746,0.4349746,0.4188566,0.4027387,0.3705029,0.338267,0.338267,0.338267,0.338267,0.338267,0.3148228,0.2679343,0.2679343,0)
est1$SURV12 <- c(0.9886175,0.9772351,0.9772351,0.9772351,0.9772351,0.9658526,0.9658526,0.9544701,0.9544701,0.9430877,0.9430877,0.9430877,0.9203227,0.9089403,0.8975578,0.8747929,0.8747929,0.8747929,
0.8632825,0.8632825,0.8632825,0.8632825,0.8402618,0.8402618,0.8283404,0.8283404,0.8283404,0.8283404,0.8283404,0.8044975,0.792576,0.792576,0.792576,0.792576,0.7684313,0.7684313,
0.7684313,0.7684313,0.7684313,0.7684313,0.7555273,0.7555273,0.7555273,0.7555273,0.7555273,0.7555273,0.7420483,0.7285693,0.7285693,0.7150902,0.7150902,0.7150902,0.7011764,0.7011764,
0.7011764,0.6872625,0.6872625,0.6872625,0.6872625,0.6733487,0.645521,0.6316072,0.6176933,0.6037795,0.6037795,0.6037795,0.6037795,0.6037795,0.589608,0.589608,0.5612649,0.5612649,
0.5612649,0.5612649,0.5612649,0.5612649,0.5470934,0.5329219,0.5045789,0.4762359,0.4620644,0.4475708,0.4475708,0.4330772,0.4330772,0.4330772,0.4330772,0.4330772,0.4330772,0.4330772,
0.4018397,0.386221,0.3701428,0.3530274,0.3530274,0.335912,0.3181853,0.3181853,0.3181853,0.3181853,0.2997768,0.2997768,0.2997768,0.2629599,0.2629599,0.2629599,0.2629599,0.2629599,
0.2629599,0.2427524,0.2225449,0.2225449,0.2225449,0.2225449,0.2225449,0.2225449,0.1637594,0.1343667,0.1343667,0.1343667,0)
est1$SURV21 <- c(1,1,0.9899313,0.9798627,0.969794,0.969794,0.9597254,0.9597254,0.9496567,0.9496567,0.939588,0.9295194,0.9295194,0.9295194,0.9295194,0.9295194,0.9192294,0.9089395,0.9089395,
0.8986495,0.8882413,0.8778331,0.8778331,0.867174,0.867174,0.8563834,0.8563834,0.8454562,0.834529,0.834529,0.834529,0.8129893,0.8017707,0.7903963,0.7903963,0.7682454,0.7567085,
0.7567085,0.7449994,0.7332903,0.7332903,0.7332903,0.7332903,0.7104575,0.6985655,0.6985655,0.6985655,0.6985655,0.6864719,0.6864719,0.6741661,0.6741661,0.6741661,0.6741661,0.6618603,
0.6618603,0.6495545,0.6495545,0.6372487,0.6372487,0.6372487,0.6372487,0.6372487,0.6372487,0.6372487,0.6246918,0.6005825,0.5764732,0.5764732,0.5639163,0.5639163,0.5513594,0.5513594,
0.5272501,0.5031408,0.5031408,0.5031408,0.5031408,0.5031408,0.5031408,0.5031408,0.5031408,0.4902699,0.4902699,0.4902699,0.4655579,0.4655579,0.4655579,0.4386654,0.4246589,0.4246589,
0.4246589,0.4246589,0.4246589,0.4102006,0.4102006,0.4102006,0.3824406,0.3546806,0.3269206,0.3269206,0.2991606,0.2847023,0.2847023,0.2847023,0.2689867,0.2532711,0.2532711,0.219921,
0.219921,0.219921,0.219921,0.219921,0.219921,0.2014655,0.1830101,0.1830101,0.1830101,0.1830101,0.163135,0)
est1$SURV22 <- c(1,1,0.9900736,0.9801472,0.9702207,0.9702207,0.9602943,0.9602943,0.9503679,0.9503679,0.9404415,0.930515,0.930515,0.930515,0.930515,0.930515,0.9203705,0.9102259,0.9102259,
0.9000813,0.8898201,0.8795589,0.8795589,0.8690505,0.8690505,0.8584123,0.8584123,0.8476394,0.8368666,0.8368666,0.8368666,0.8368666,0.8258065,0.8145928,0.8145928,0.8145928,
0.8032188,0.8032188,0.7916751,0.7801315,0.7801315,0.7801315,0.7556639,0.7556639,0.7439398,0.7194722,0.7194722,0.7194722,0.7075494,0.7075494,0.6954175,0.6700987,0.6700987,
0.6447798,0.6326479,0.6326479,0.620516,0.5951971,0.5830652,0.5830652,0.5830652,0.5830652,0.5830652,0.5830652,0.5572296,0.5448501,0.5448501,0.5448501,0.5448501,0.5324706,
0.5324706,0.5200911,0.5200911,0.5200911,0.5200911,0.5200911,0.5200911,0.5200911,0.5200911,0.5200911,0.5200911,0.5200911,0.507402,0.507402,0.4809206,0.4809206,0.4809206,
0.4809206,0.4809206,0.467112,0.467112,0.467112,0.467112,0.467112,0.4528579,0.4528579,0.4528579,0.4528579,0.4528579,0.4528579,0.4528579,0.4528579,0.4386038,0.4386038,
0.4386038,0.4231102,0.4076167,0.4076167,0.4076167,0.4076167,0.4076167,0.4076167,0.4076167,0.3718787,0.3536839,0.3354892,0.3354892,0.3354892,0.3354892,0.3158948,0)
est1$SE11 <- c(0.01008932,0.0142519,0.0142519,0.0142519,0.0142519,0.01743465,0.01743465,0.02010834,0.02010834,0.02245554,0.02245554,0.02245554,0.02245554,0.02457002,0.0265075,0.0265075,
0.0265075,0.0265075,0.02834454,0.02834454,0.02834454,0.02834454,0.02834454,0.02834454,0.03018546,0.03018546,0.03610194,0.03610194,0.03610194,0.03610194,0.0374836,0.0374836,
0.0374836,0.0374836,0.0374836,0.0374836,0.0374836,0.04258293,0.04258293,0.04258293,0.04388882,0.04836124,0.04836124,0.04836124,0.04836124,0.04836124,0.04954111,0.05068235,
0.05068235,0.0517875,0.0517875,0.0517875,0.05294031,0.05294031,0.05294031,0.05405628,0.05405628,0.05405628,0.05405628,0.05513766,0.05513766,0.05618644,0.05720442,0.0581932,
0.0581932,0.0581932,0.0581932,0.0581932,0.05919844,0.05919844,0.05919844,0.05919844,0.06217695,0.06217695,0.06217695,0.06475392,0.06549431,0.06621545,0.06621545,0.06621545,
0.06691795,0.06764974,0.06764974,0.0683617,0.0683617,0.0683617,0.07046828,0.07234202,0.07234202,0.07234202,0.07234202,0.07296969,0.07364174,0.07444681,0.07444681,0.07521751,
0.07605253,0.07605253,0.07605253,0.07605253,0.07696186,0.07696186,0.07696186,0.07696186,0.07841019,0.07841019,0.07841019,0.07951929,0.07951929,0.08028699,0.08099307,0.08120743,
0.0806924,0.0806924,0.0806924,0.0806924,0.0806924,0.08266642,0.08181639,0.08181639,0)
est1$SE12 <- c(0.01008263,0.01423295,0.01423295,0.01423295,0.01423295,0.01739978,0.01739978,0.02005457,0.02005457,0.02238029,0.02238029,0.02238029,0.02945466,0.03097414,0.03241104,0.03719364,
0.03719364,0.03719364,0.03833557,0.03833557,0.03833557,0.03833557,0.04221069,0.04221069,0.04321132,0.04321132,0.04321132,0.04321132,0.04321132,0.04660017,0.04742152,0.04742152,
0.04742152,0.04742152,0.05027956,0.05027956,0.05027956,0.05027956,0.05027956,0.05027956,0.0511015,0.0511015,0.0511015,0.0511015,0.0511015,0.0511015,0.05198352,0.05283305,0.05283305,
0.05365163,0.05365163,0.05365163,0.05450419,0.05450419,0.05450419,0.05532374,0.05532374,0.05532374,0.05532374,0.05611171,0.05836339,0.05898312,0.05957794,0.06014859,0.06014859,
0.06014859,0.06014859,0.06014859,0.06072482,0.06072482,0.06211516,0.06211516,0.06211516,0.06211516,0.06211516,0.06211516,0.06254365,0.06294998,0.06372057,0.06412774,0.06429083,
0.06445696,0.06445696,0.06460129,0.06460129,0.06460129,0.06460129,0.06460129,0.06460129,0.06460129,0.06438604,0.06442937,0.0644673,0.06452867,0.06452867,0.06453804,0.06452758,
0.06452758,0.06452758,0.06452758,0.06448879,0.06448879,0.06448879,0.06218416,0.06218416,0.06218416,0.06218416,0.06218416,0.06218416,0.06179852,0.06128618,0.06128618,0.06128618,
0.06128618,0.06128618,0.06128618,0.05193302,0.04926495,0.04926495,0.04926495,0)
est1$SE21 <- c(0,0,0.009984863,0.01409929,0.017241736,0.017241736,0.019878631,0.019878631,0.022190931,0.022190931,0.024271586,0.026175893,0.026175893,0.026175893,0.026175893,0.026175893,
0.028016956,0.029732817,0.029732817,0.031344043,0.032901267,0.034377488,0.034377488,0.035852064,0.035852064,0.037292718,0.037292718,0.03870412,0.04005408,0.04005408,0.04005408,
0.04420901,0.045373907,0.046531731,0.046531731,0.049969355,0.050968028,0.050968028,0.051968208,0.052936766,0.052936766,0.052936766,0.052936766,0.055715198,0.056563231,0.056563231,
0.056563231,0.056563231,0.057420048,0.057420048,0.058286318,0.058286318,0.058286318,0.058286318,0.059125143,0.059125143,0.059937678,0.059937678,0.060724977,0.060724977,0.060724977,
0.060724977,0.060724977,0.060724977,0.060724977,0.061528781,0.063437358,0.065032035,0.065032035,0.065606801,0.065606801,0.066161927,0.066161927,0.067285842,0.068144906,0.068144906,
0.068144906,0.068144906,0.068144906,0.068144906,0.068144906,0.068144906,0.068547161,0.068547161,0.068547161,0.069123954,0.069123954,0.069123954,0.069620392,0.069927724,0.069927724,
0.069927724,0.069927724,0.069927724,0.070258255,0.070258255,0.070258255,0.070196775,0.069733617,0.068860678,0.068860678,0.067562074,0.06731866,0.06731866,0.06731866,0.067110856,
0.066850098,0.066850098,0.064080655,0.064080655,0.064080655,0.064080655,0.064080655,0.064080655,0.063566509,0.062918164,0.062918164,0.062918164,0.062918164,0.06216245,0)
est1$SE22 <- c(0,0,0.009991568,0.014118278,0.01727666,0.01727666,0.019932462,0.019932462,0.022266253,0.022266253,0.024370717,0.026300962,0.026300962,0.026300962,0.026300962,0.026300962,
0.028170462,0.029916693,0.029916693,0.031560123,0.033151628,0.034663842,0.034663842,0.036176818,0.036176818,0.03765795,0.03765795,0.039111925,0.040506105,0.040506105,0.040506105,
0.040506105,0.041919604,0.043317035,0.043317035,0.043317035,0.044701189,0.044701189,0.046075344,0.047399544,0.047399544,0.047399544,0.051692572,0.051692572,0.052814595,0.056299196,
0.056299196,0.056299196,0.057274561,0.057274561,0.058261996,0.061185298,0.061185298,0.06366198,0.064372114,0.064372114,0.065064519,0.066938481,0.067514085,0.067514085,0.067514085,
0.067514085,0.067514085,0.067514085,0.069029034,0.06952516,0.06952516,0.06952516,0.06952516,0.070007162,0.070007162,0.070475331,0.070475331,0.070475331,0.070475331,0.070475331,0.070475331,
0.070475331,0.070475331,0.070475331,0.070475331,0.070475331,0.0709692,0.0709692,0.071851337,0.071851337,0.071851337,0.071851337,0.071851337,0.072374395,0.072374395,0.072374395,0.072374395,
0.072374395,0.072934476,0.072934476,0.072934476,0.072934476,0.072934476,0.072934476,0.072934476,0.072934476,0.073465995,0.073465995,0.073465995,0.074172885,0.074835469,0.074835469,
0.074835469,0.074835469,0.074835469,0.074835469,0.074835469,0.075531752,0.076366116,0.077109446,0.077109446,0.077109446,0.077109446,0.078053426,0)
#Reformat results for ggplot
group = c(rep("A1B1", length(est1$t)), rep("A1B2", length(est1$t)), rep("A2B1", length(est1$t)), rep("A2B2", length(est1$t)))
time = rep(est1$t, 4)
surv = c(est1$SURV11, est1$SURV12, est1$SURV21, est1$SURV22)
se = c(est1$SE11, est1$SE12, est1$SE21, est1$SE22)
plot.result <- data.frame(group, time, surv, se)
g <- ggplot(plot.result) +
geom_step(aes(x=time, y=surv, color=group), size=1.2) +
scale_color_manual(values=line.color) +
xlab(xlab) + ylab(ylab) +
theme_bw() +
theme(title=element_text(size=15), axis.text=element_text(size=15),
legend.position=legend.position, legend.title=element_blank(),
legend.text=element_text(size=15), legend.key.size=unit(1, "cm"))
g <- g +
geom_step(aes(x=time, y=surv-1.96*se, color=group), linetype='dotted', size=0.5) +
geom_step(aes(x=time, y=surv+1.96*se, color=group), linetype='dotted', size=0.5)
g