library(ggplot2)
head(iris)
plot(iris$Sepal.Length, iris$Sepal.Width, col=iris$Species)
ggplot(data=iris, aes(x=Sepal.Length, y=Sepal.Width, color=Species)) + geom_point(size=3)
ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width, color=Species)) +
geom_point(size=2) +
geom_smooth(method=lm)
boxplot(Sepal.Length~Species, data=iris, ylab='Sepal length')
p <- ggplot(iris, aes(factor(Species), Sepal.Length))
p + geom_boxplot() + geom_jitter(position = position_jitter(width = .1))
ggplot(iris, aes(x=Sepal.Length, fill=Species)) +
geom_histogram(binwidth=.5, alpha=.5, position="identity")
ggplot(iris, aes(x=Sepal.Length, fill=Species)) + geom_density(alpha=.3)
# install.packages('ggExtra')
# create dataset with 1000 normally distributed points
df <- data.frame(x = rnorm(1000, 50, 10), y = rnorm(1000, 50, 10))
# create a ggplot2 scatterplot
p <- ggplot(df, aes(x, y)) + geom_point() + theme_classic()
# add marginal histograms
ggExtra::ggMarginal(p, type = "histogram")