ggplot2
Tutorial exercises
Last updated
Tutorial exercises
Last updated
-- https://github.com/GladB/ggplot_tutorial/blob/master/to_present.Rmd
ggplot(iris, aes(Sepal.Length, Petal.Length))+
geom_point(aes(color=Sepal.Width))+
geom_smooth(method="lm")+
theme_bw()
ggplot(iris, aes(x=Species, y=Petal.Length, color=Species, fill=Species)) +
geom_boxplot(width = 0.6, alpha=0.5)+
geom_jitter(width=0.1, height=0)+
geom_violin(alpha = 0.5, fill="grey")
ggplot(iris, aes(x=Species, y=Petal.Length, color=Species, fill=Species)) +
geom_jitter(width=0.1, height=0)+
geom_violin(alpha = 0.5, fill="grey")+
geom_boxplot(width = 0.6, alpha=0.5)
ggplot(iris, aes(x=Species, y=Petal.Length, color=Species, fill=Species)) +
geom_jitter(width=0.1, alpha=0.5)+
geom_violin(alpha = 0.5, fill="grey", position = position_nudge(x=0.6))+
geom_boxplot(width = 0.3, alpha=0.5)+
coord_flip()+
theme_classic()
ggplot()+
geom_histogram(aes(x=Sepal.Length), fill="green", alpha = 0.5, data=iris)+
geom_histogram(aes(x=Petal.Length), fill="red", alpha=0.5, data=iris)+
facet_wrap(~Species)+
theme_dark()+
labs(x="Length of sepals (green), length of petals (red)", y="Number of flowers with these features")
ggplot(iris, aes(x=Sepal.Width))+
geom_histogram(aes(fill=Species), color="black")+
xlab("Sepal width")+
ylab("Count")+
ggtitle("Histogram of sepal width")
ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width))+
geom_point(aes(color=Petal.Width, shape=Species), size=2)+
scale_color_gradient(low = "yellow", high = "red")+
theme_grey()