Data
iris
Shapiro-Wilk test
H0 : the variable follow a normal distribution
H1 : the variable NOT follow a normal distribution
library(RVAideMemoire)
## *** Package RVAideMemoire v 0.9-80 ***
byf.shapiro(Sepal.Length~Species,data=iris)
##
## Shapiro-Wilk normality tests
##
## data: Sepal.Length by Species
##
## W p-value
## setosa 0.9777 0.4595
## versicolor 0.9778 0.4647
## virginica 0.9712 0.2583
OR
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ ggplot2 3.3.5 ✓ purrr 0.3.4
## ✓ tibble 3.1.5 ✓ dplyr 1.0.7
## ✓ tidyr 1.1.4 ✓ stringr 1.4.0
## ✓ readr 2.0.2 ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(rstatix)
##
## Attaching package: 'rstatix'
## The following object is masked from 'package:stats':
##
## filter
iris %>%
group_by(Species) %>%
shapiro_test(Sepal.Length)
Sepal.Length variable for each groups :
p-value > 0.05 Accept H0,the p values are not statistically significant (the variable follow a normal distribution)
Q-Q plot using ggplot2
library(ggplot2)
library(qqplotr)
##
## Attaching package: 'qqplotr'
## The following objects are masked from 'package:ggplot2':
##
## stat_qq_line, StatQqLine
ggplot(data = iris, mapping = aes(sample = Sepal.Length, fill = Species))+
stat_qq_band(alpha=0.15) +stat_qq_line(alpha=0.15) +stat_qq_point(size=0.5) + facet_wrap(~ Species) +labs(title = "Normal Q-Q plot", x = "Theoretical Quantiles", y = "Sample Quantiles")+theme_bw()
Density plot using ggplot2
Using facet_wrap()
ggplot(data=iris,aes(x = Sepal.Length, fill = Species)) +
geom_density(alpha=0.15) +
facet_wrap(Species ~ .)+theme_bw()
Using facet_grid()
ggplot(data=iris,aes(x = Sepal.Length, fill = Species)) +
geom_density(alpha=0.15) +
facet_grid(Species ~ .)+theme_bw()
Multiple Overlay density plots using ggplot2
ggplot(data=iris, aes(x = Sepal.Length, fill = Species)) +
geom_density(alpha = 0.15)+labs(title = "Density plot with multiple groups")+theme_bw()
Histogram plot using ggplot2
Using facet_wrap()
ggplot(data = iris, aes(x = Sepal.Length,fill=Species)) +
geom_histogram(alpha=0.15) +
facet_wrap(Species ~ .)+theme_bw()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
Using facet_grid()
ggplot(data = iris, aes(x = Sepal.Length,fill=Species)) +
geom_histogram(alpha=0.15) +
facet_grid(Species ~ .)+theme_bw()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
Multiple Overlaid Histograms using ggplot2
ggplot(data = iris, aes(x = Sepal.Length,fill=Species)) +
geom_histogram(alpha = 0.15, position = "identity")+
labs(title = "Histogram with multiple groups")+theme_bw()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.