my site: https://b04902122.github.io/CSX_R/week_3/ggplot2.html

ggplot2

library(ggplot2)

bar chart

ggplot(data=iris, aes(x=Species, y=Sepal.Length, fill=Species)) +
    geom_bar(stat="identity") +
    guides(fill=FALSE)

pie chart

ggplot(data = iris,
  aes(x = factor(""), fill = Species) ) +
  geom_bar() +
  coord_polar(theta = "y") +
  scale_x_discrete("")

scatter chart

ggplot(iris, aes(Sepal.Length, Sepal.Width, color=Species)) +
  geom_point()

scatter with trend line chart

ggplot(data=iris,aes(x=Sepal.Width, y=Sepal.Length,color=Species)) + geom_point() +geom_smooth(se=FALSE)+
 theme_minimal()
## `geom_smooth()` using method = 'loess'

line chart

ggplot(iris, aes(Sepal.Length, Sepal.Width, color=Species)) +
  geom_line()

histogram chart

ggplot(data = iris, aes(x = Sepal.Length,color=Species)) +
geom_histogram()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

frequency polygons chart

ggplot(iris, aes(x=Petal.Length, color=Species)) +
  geom_freqpoly()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

boxplot chart

ggplot(iris, aes(x=Petal.Length, y=Petal.Width, color=Species)) +
geom_boxplot()
## Warning: position_dodge requires non-overlapping x intervals

density curve chart

ggplot(data=iris,aes(x=Sepal.Length,color=Species)) + geom_density() +theme_minimal()

density2d curve chart

ggplot(data=iris,aes(x=Petal.Width,y=Petal.Length,color=Species)) +geom_density2d()+ theme_minimal()