library(ggplot2)
setosa <- iris[iris$Species=="setosa",]
versicolor <- iris[iris$Species=="versicolor",]
virginica <- iris[iris$Species=="virginica",]
summary(setosa)
## Sepal.Length Sepal.Width Petal.Length Petal.Width
## Min. :4.300 Min. :2.300 Min. :1.000 Min. :0.100
## 1st Qu.:4.800 1st Qu.:3.200 1st Qu.:1.400 1st Qu.:0.200
## Median :5.000 Median :3.400 Median :1.500 Median :0.200
## Mean :5.006 Mean :3.428 Mean :1.462 Mean :0.246
## 3rd Qu.:5.200 3rd Qu.:3.675 3rd Qu.:1.575 3rd Qu.:0.300
## Max. :5.800 Max. :4.400 Max. :1.900 Max. :0.600
## Species
## setosa :50
## versicolor: 0
## virginica : 0
##
##
##
setosa_sl <- summary(setosa$Sepal.Length)[c(1,6)]
hist(setosa$Sepal.Length, main="Setosa Sepal Length", xlab="Sepal Length",
xlim=c(floor(setosa_sl[1]),ceiling(setosa_sl[2])),
breaks=seq(floor(setosa_sl[1]),ceiling(setosa_sl[2]),.2))
setosa_sw <- summary(setosa$Sepal.Width)[c(1,6)]
hist(setosa$Sepal.Width, main="Setosa Sepal Width", xlab="Sepal Width",
xlim=c(floor(setosa_sw[1]),ceiling(setosa_sw[2])),
breaks=seq(floor(setosa_sw[1]),ceiling(setosa_sw[2]),.2))
setosa_pl <- summary(setosa$Petal.Length)[c(1,6)]
hist(setosa$Petal.Length, main="Setosa Petal Length", xlab="Petal Length",
xlim=c(floor(setosa_pl[1]),ceiling(setosa_pl[2])),
breaks=seq(floor(setosa_pl[1]),ceiling(setosa_pl[2]),.2))
setosa_pw <- summary(setosa$Petal.Width)[c(1,6)]
hist(setosa$Petal.Width, main="Setosa Petal Width", xlab="Petal Width",
xlim=c(floor(setosa_pw[1]),ceiling(setosa_pw[2])),
breaks=seq(floor(setosa_pw[1]),ceiling(setosa_pw[2]),.2))
summary(versicolor)
## Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## Min. :4.900 Min. :2.000 Min. :3.00 Min. :1.000 setosa : 0
## 1st Qu.:5.600 1st Qu.:2.525 1st Qu.:4.00 1st Qu.:1.200 versicolor:50
## Median :5.900 Median :2.800 Median :4.35 Median :1.300 virginica : 0
## Mean :5.936 Mean :2.770 Mean :4.26 Mean :1.326
## 3rd Qu.:6.300 3rd Qu.:3.000 3rd Qu.:4.60 3rd Qu.:1.500
## Max. :7.000 Max. :3.400 Max. :5.10 Max. :1.800
versicolor_sl <- summary(versicolor$Sepal.Length)[c(1,6)]
hist(versicolor$Sepal.Length, main="Versicolor Sepal Length", xlab="Sepal Length",
xlim=c(floor(versicolor_sl[1]),ceiling(versicolor_sl[2])),
breaks=seq(floor(versicolor_sl[1]),ceiling(versicolor_sl[2]),.2))
versicolor_sw <- summary(versicolor$Sepal.Width)[c(1,6)]
hist(versicolor$Sepal.Width, main="Versicolor Sepal Width", xlab="Sepal Width",
xlim=c(floor(versicolor_sw[1]),ceiling(versicolor_sw[2])),
breaks=seq(floor(versicolor_sw[1]),ceiling(versicolor_sw[2]),.2))
versicolor_pl <- summary(versicolor$Petal.Length)[c(1,6)]
hist(versicolor$Petal.Length, main="Versicolor Petal Length", xlab="Petal Length",
xlim=c(floor(versicolor_pl[1]),ceiling(versicolor_pl[2])),
breaks=seq(floor(versicolor_pl[1]),ceiling(versicolor_pl[2]),.2))
versicolor_pw <- summary(versicolor$Petal.Width)[c(1,6)]
hist(versicolor$Petal.Width, main="Versicolor Petal Width", xlab="Petal Width",
xlim=c(floor(versicolor_pw[1]),ceiling(versicolor_pw[2])),
breaks=seq(floor(versicolor_pw[1]),ceiling(versicolor_pw[2]),.2))
summary(virginica)
## Sepal.Length Sepal.Width Petal.Length Petal.Width
## Min. :4.900 Min. :2.200 Min. :4.500 Min. :1.400
## 1st Qu.:6.225 1st Qu.:2.800 1st Qu.:5.100 1st Qu.:1.800
## Median :6.500 Median :3.000 Median :5.550 Median :2.000
## Mean :6.588 Mean :2.974 Mean :5.552 Mean :2.026
## 3rd Qu.:6.900 3rd Qu.:3.175 3rd Qu.:5.875 3rd Qu.:2.300
## Max. :7.900 Max. :3.800 Max. :6.900 Max. :2.500
## Species
## setosa : 0
## versicolor: 0
## virginica :50
##
##
##
virginica_sl <- summary(virginica$Sepal.Length)[c(1,6)]
hist(virginica$Sepal.Length, main="Virginica Sepal Length", xlab="Sepal Length",
xlim=c(floor(virginica_sl[1]),ceiling(virginica_sl[2])),
breaks=seq(floor(virginica_sl[1]),ceiling(virginica_sl[2]),.2))
virginica_sw <- summary(virginica$Sepal.Width)[c(1,6)]
hist(virginica$Sepal.Width, main="Virginica Sepal Width", xlab="Sepal Width",
xlim=c(floor(virginica_sw[1]),ceiling(virginica_sw[2])),
breaks=seq(floor(virginica_sw[1]),ceiling(virginica_sw[2]),.2))
virginica_pl <- summary(virginica$Petal.Length)[c(1,6)]
hist(virginica$Petal.Length, main="Virginica Petal Length", xlab="Petal Length",
xlim=c(floor(virginica_pl[1]),ceiling(virginica_pl[2])),
breaks=seq(floor(virginica_pl[1]),ceiling(virginica_pl[2]),.2))
virginica_pw <- summary(virginica$Petal.Width)[c(1,6)]
hist(virginica$Petal.Width, main="Virginica Petal Width", xlab="Petal Width",
xlim=c(floor(virginica_pw[1]),ceiling(virginica_pw[2])),
breaks=seq(floor(virginica_pw[1]),ceiling(virginica_pw[2]),.2))
qplot(data=iris, x=Species, y=Sepal.Length, geom="boxplot", main="Sepal Length")
## Warning: `qplot()` was deprecated in ggplot2 3.4.0.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## Sepal Width
qplot(data=iris, x=Species, y=Sepal.Width, geom="boxplot", main="Sepal Width")
qplot(data=iris, x=Species, y=Petal.Length, geom="boxplot", main="Petal Length")
qplot(data=iris, x=Species, y=Petal.Width, geom="boxplot", main="Petal Width")
qplot(data=iris, x=Sepal.Width, y=Sepal.Length, color=Species, size=I(3),
shape=I(19), alpha=I(.5), main="Sepal Length vs Sepal Width")
qplot(data=iris, x=Petal.Width, y=Petal.Length, color=Species, size=I(3),
shape=I(19), alpha=I(.5), xlab="Petal Width", ylab="Petal Length",
main="Petal Length vs Petal Width")
Manual Manipulation without Tidyverse
library(ggplot2)
cm=c(iris$Sepal.Length, iris$Sepal.Width, iris$Petal.Length, iris$Petal.Width)
value_name=c(rep('Sepal Length', 150), rep('Sepal Width', 150), rep('Petal Length', 150), rep ('Petal Width', 150))
species=rep(iris$Species,4)
tmp=cbind(cm, value_name, species)
mydf=data.frame(tmp, stringsAsFactors = T)
mydf$cm=as.numeric(mydf$cm)
levels(mydf$species)=c('Setosa','Versicolor', 'Virginica')
myplot=ggplot(data=mydf, aes(x=species, y=cm, col=species))+
geom_boxplot(notch=TRUE, outlier.color='black')+
facet_wrap(.~value_name, scales='free')+
coord_flip()
myplot
## Notch went outside hinges
## ℹ Do you want `notch = FALSE`?
library(ResourceSelection)
## ResourceSelection 0.3-5 2019-07-22
kdepairs(iris[,1:4])
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter