#Create a scatterplot of sepal length with sepal width, facet by species. Run a regression on the plot using geom_smooth.
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.0.2
data<-iris
x<-ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width))+
geom_point(mapping = NULL, col="BLue", size=1)+
geom_smooth(method="lm", col="firebrick") +
labs(title="Sepal length with Sepal width",
subtitle="From iris dataset",
y="Sepal.Width",
x="Sepal.Length")+
facet_wrap(~Species, nrow=2)+
scale_colour_brewer(palette = "Set1")+
theme_classic() + labs(subtitle="Classic Theme")+
theme(legend.position="None")
print(x)
## `geom_smooth()` using formula 'y ~ x'
library(plotly)
## Warning: package 'plotly' was built under R version 4.0.2
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
ggplotly(x)
## `geom_smooth()` using formula 'y ~ x'
## Warning: `group_by_()` is deprecated as of dplyr 0.7.0.
## Please use `group_by()` instead.
## See vignette('programming') for more help
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_warnings()` to see where this warning was generated.
#Create a histogram of sepal length, change the bin size as convenient. Add a frequency polygon.
library(ggplot2)
y<-ggplot(data = iris, aes(Sepal.Length)) +
geom_histogram(col="green") +
geom_freqpoly(stat = "bin", col= "red", size= 1) +
stat_bin(bins=30, binwidth = 0.10)+
labs(title="Histogram of Sepal.Length",
subtitle="From iris dataset",
x="Sepal.Length")
y
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
library(plotly)
ggplotly(y)
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
#Create a Boxplot of petal length with species
library(ggplot2)
z<-ggplot(data=iris, aes(Petal.Length, Species))+
geom_boxplot(varwidth= TRUE,
fill = "white", notch = TRUE, colour = "blue",
outlier.colour = "red", outlier.shape = 4) +
coord_flip()+theme_bw()
z
library(plotly)
ggplotly(z)
#Use par mfrow to create 2 histograms for petal length and petal width, side by side. Comment on the distributions.
par(mfrow=c(1,2))
plot(iris$Petal.Length, col="blue")
plot(iris$Petal.Width, col="firebrick")