Vis 1
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 3.3.3
data(mpg)
str(mpg)
## Classes 'tbl_df', 'tbl' and 'data.frame': 234 obs. of 11 variables:
## $ manufacturer: chr "audi" "audi" "audi" "audi" ...
## $ model : chr "a4" "a4" "a4" "a4" ...
## $ displ : num 1.8 1.8 2 2 2.8 2.8 3.1 1.8 1.8 2 ...
## $ year : int 1999 1999 2008 2008 1999 1999 2008 1999 1999 2008 ...
## $ cyl : int 4 4 4 4 6 6 6 4 4 4 ...
## $ trans : chr "auto(l5)" "manual(m5)" "manual(m6)" "auto(av)" ...
## $ drv : chr "f" "f" "f" "f" ...
## $ cty : int 18 21 20 21 16 18 18 18 16 20 ...
## $ hwy : int 29 29 31 30 26 26 27 26 25 28 ...
## $ fl : chr "p" "p" "p" "p" ...
## $ class : chr "compact" "compact" "compact" "compact" ...
g <- ggplot(mpg, aes(class))
g + geom_bar(aes(fill = trans))+ guides(fill=guide_legend(title="Transmission"))

Vis 2
library(ggthemes)
## Warning: package 'ggthemes' was built under R version 3.3.3
g2 <- ggplot(mpg, aes(manufacturer, hwy))
g2 + geom_boxplot() + coord_flip() + labs(x = "Vehicle Manufacturer",y ="Highway Fuel Efficiency (miles/gallon)")+ theme_tufte()+ theme_classic()

Vis 3
data("diamonds")
head(diamonds)
## # A tibble: 6 x 10
## carat cut color clarity depth table price x y z
## <dbl> <ord> <ord> <ord> <dbl> <dbl> <int> <dbl> <dbl> <dbl>
## 1 0.23 Ideal E SI2 61.5 55 326 3.95 3.98 2.43
## 2 0.21 Premium E SI1 59.8 61 326 3.89 3.84 2.31
## 3 0.23 Good E VS1 56.9 65 327 4.05 4.07 2.31
## 4 0.29 Premium I VS2 62.4 58 334 4.20 4.23 2.63
## 5 0.31 Good J SI2 63.3 58 335 4.34 4.35 2.75
## 6 0.24 Very Good J VVS2 62.8 57 336 3.94 3.96 2.48
library(ggthemes)
g3 <- ggplot(diamonds, aes(price,color=cut,fill=cut))
g3 + geom_density(alpha = 0.2) +labs(y ="Density", x = "Diamond Price (USD)") + ggtitle('Diamond Price Density')+ theme_economist()

Vis 4
head(iris)
## Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## 1 5.1 3.5 1.4 0.2 setosa
## 2 4.9 3.0 1.4 0.2 setosa
## 3 4.7 3.2 1.3 0.2 setosa
## 4 4.6 3.1 1.5 0.2 setosa
## 5 5.0 3.6 1.4 0.2 setosa
## 6 5.4 3.9 1.7 0.4 setosa
ggplot(iris, aes(Sepal.Length, Petal.Length)) +
geom_point() +
geom_smooth(method="lm")+labs(x="Iris Sepal Length",y="Iris Petal Length")+ggtitle('Relationship between Petal and Sepal Length')+ theme_minimal()

Vis 5
ggplot(iris, aes(Sepal.Length, Petal.Length, colour = Species)) +
geom_point() +
geom_smooth(se = FALSE, method = "lm")+labs(x="Iris Sepal Length",y="Iris Petal Length")+ggtitle('Relationship between Petal and Sepal Length',subtitle="Species level comparison")+theme_tufte()+theme(legend.position = "bottom")
