The function stat_mean_ci from the tern package can be used with default values to draw the 95% confidence interval around the mean.
Code
plot <-ggplot(data = adlb,mapping =aes(x = ARMCD, y = AVAL, color = SEX,lty = SEX, shape = SEX )) +stat_summary(fun.data = tern::stat_mean_ci,geom ="errorbar",width =0.1,position =position_dodge(width =0.5) ) +stat_summary(fun = mean,geom ="point",position =position_dodge(width =0.5) ) +labs(title ="Confidence Interval Plot by Treatment Group",caption ="Mean and 95% CIs for mean are displayed.",x ="Treatment Group",y =paste0(adlb$PARAMCD[1], " (", adlb$AVALU[1], ")") )plot
Experimental use!
WebR is a tool allowing you to run R code in the web browser. Modify the code below and click run to see the results. Alternatively, copy the code and click here to open WebR in a new tab.
plot <-ggplot(data = adlb,mapping =aes(x = ARMCD, y = AVAL, color = STRATA2,lty = STRATA2, shape = STRATA2 )) +stat_summary(fun.data = tern::stat_mean_ci,geom ="errorbar",width =0.1,position =position_dodge(width =0.5) ) +stat_summary(fun = mean,geom ="point",position =position_dodge(width =0.5) ) +labs(title ="Confidence Interval Plot by Treatment Group",caption ="Mean and 95% CIs for mean are displayed.",x ="Treatment Group",y =paste0(adlb$PARAMCD[1], " (", adlb$AVALU[1], ")") )plot
Experimental use!
WebR is a tool allowing you to run R code in the web browser. Modify the code below and click run to see the results. Alternatively, copy the code and click here to open WebR in a new tab.
The function stat_median_ci from the tern package works similarly to stat_mean_ci.
Code
plot <-ggplot(data = adlb,mapping =aes(x = ARMCD, y = AVAL, color = STRATA1,lty = STRATA1, shape = STRATA1 )) +stat_summary(fun.data = stat_median_ci,geom ="errorbar",width =0.1,position =position_dodge(width =0.5) ) +stat_summary(fun = median,geom ="point",position =position_dodge(width =0.5) ) +labs(title ="Confidence Interval Plot by Treatment Group",caption ="Median and 95% CIs for median are displayed.",x ="Treatment Group",y =paste0(adlb$PARAMCD[1], " (", adlb$AVALU[1], ")") )plot
Experimental use!
WebR is a tool allowing you to run R code in the web browser. Modify the code below and click run to see the results. Alternatively, copy the code and click here to open WebR in a new tab.
To modify the confidence level for the estimation of the confidence interval, the call to stat_mean_ci (or stat_median_ci) can be slightly modified.
Code
plot <-ggplot(data = adlb,mapping =aes(x = ARMCD, y = AVAL, color = SEX,lty = SEX, shape = SEX )) +stat_summary(fun.data =function(x) tern::stat_mean_ci(x, conf_level =0.9),geom ="errorbar",width =0.1,position =position_dodge(width =0.5) ) +stat_summary(fun = mean,geom ="point",position =position_dodge(width =0.5) ) +labs(title ="Confidence Interval Plot by Treatment Group",caption ="Mean and 90% CIs for mean are displayed.",x ="Treatment Group",y =paste0(adlb$PARAMCD[1], " (", adlb$AVALU[1], ")") )plot
Experimental use!
WebR is a tool allowing you to run R code in the web browser. Modify the code below and click run to see the results. Alternatively, copy the code and click here to open WebR in a new tab.
ARM A ARM B ARM C
————————————————————————————————————————————————
Mean (SD) 17.7 (9.9) 18.7 (9.8) 19.5 (9.1)
Median 17.5 18.2 19.0
Experimental use!
WebR is a tool allowing you to run R code in the web browser. Modify the code below and click run to see the results. Alternatively, copy the code and click here to open WebR in a new tab.
shinylive allow you to modify to run shiny application entirely in the web browser. Modify the code below and click re-run the app to see the results. The performance is slighly worse and some of the features (e.g. downloading) might not work at all.