R Markdown

Install required R packages

install.packages(“dplyr”, dependencies = TRUE)

ggpubr for an easy ggplot2-based data visualization

` ## Install

install.packages(“ggpubr”, dependencies = TRUE)

Load required R packages

library("dplyr")
## Warning: package 'dplyr' was built under R version 4.3.2
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library("ggpubr")
## Warning: package 'ggpubr' was built under R version 4.3.2
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 4.3.2

Import your data into R

# Store the data in the variable my_data
my_data <- ToothGrowth

Check your data

set.seed(1234)
dplyr::sample_n(my_data, 10)
##     len supp dose
## 1  21.5   VC  2.0
## 2  17.3   VC  1.0
## 3  27.3   OJ  2.0
## 4  18.5   VC  2.0
## 5   8.2   OJ  0.5
## 6  26.4   OJ  1.0
## 7  25.8   OJ  1.0
## 8   5.2   VC  0.5
## 9   6.4   VC  0.5
## 10  9.4   OJ  0.5

Visual methods

Density plot: the density plot provides a visual judgment about whether the distribution is bell shaped.

library("ggpubr")
ggdensity(my_data$len, 
          main = "Density plot of tooth length",
          xlab = "Tooth length")

Q-Q plot: Q-Q plot (or quantile-quantile plot) draws the correlation between a given sample and the normal distribution. A 45-degree reference line is also plotted.

library(ggpubr)
ggqqplot(my_data$len)

Normality test

shapiro.test(my_data$len)
## 
##  Shapiro-Wilk normality test
## 
## data:  my_data$len
## W = 0.96743, p-value = 0.1091

From the output, the p-value > 0.05 implying that the distribution of the data are not significantly different from normal distribution. In other words, we can assume the normality.