Barplots, boxplots or normality plots are displayed according to the nature of described variable. These plots are useful to explore visually whether a continuous variable follows a normal distribution or to identify possible outliers or rare categories, etc.
knitr::opts_chunk$set(comment="",message=FALSE,warning=FALSE)
Install compareGroups
package from CRAN and then load it by typing:
install.packages("compareGroups") library(compareGroups)
library(compareGroups)
Load the REGICOR example data available in compareGroups
package:
data(regicor)
First use compareGroups
function to store all values used to perform plots afterwards.
res <- compareGroups(year ~ . , data = regicor)
You can use varinfo
function to recover the original name of variables (not labels which are displayed in the results).
varinfo(res)
by using the plot
method which takes the results created by compareGroups
function. Inside "[" brackets you can select which variable to plot. And, indicating bivar=TRUE
a bivariate plot is performed, i.e. stratifying by groups.
a. For categorical variables a barplot is performed, stratifying by groups (right plot) or not (left plot):
plot(res['sex'])
plot(res['sex'], bivar=TRUE)
b. For continuous variables boxplots or normality plots are performed depending whether groups are considered or not, respectively.
plot(res['bmi'])
plot(res['bmi'],bivar=TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.