In [1]:
library(ggplot2)
In [4]:
head(iris)
Out[4]:
Sepal.LengthSepal.WidthPetal.LengthPetal.WidthSpecies
15.13.51.40.2setosa
24.931.40.2setosa
34.73.21.30.2setosa
44.63.11.50.2setosa
553.61.40.2setosa
65.43.91.70.4setosa

Scatter plot

In [13]:
plot(iris$Sepal.Length, iris$Sepal.Width, col=iris$Species)
In [9]:
ggplot(data=iris, aes(x=Sepal.Length, y=Sepal.Width, color=Species)) + geom_point(size=3)
In [49]:
ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width, color=Species)) +
    geom_point(size=2) +    
    geom_smooth(method=lm)

Boxplot diagram

In [8]:
boxplot(Sepal.Length~Species, data=iris, ylab='Sepal length')
In [54]:
p <- ggplot(iris, aes(factor(Species), Sepal.Length))
p + geom_boxplot() + geom_jitter(position = position_jitter(width = .1))

Histograms

In [31]:
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)

Scatter plot with histograms

In [33]:
# 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")
stat_bin: binwidth defaulted to range/30. Use 'binwidth = x' to adjust this.