library(ggplot2)
## Warning: package 'ggplot2' was built under R version 3.3.2
library(dplyr)
## Warning: package 'dplyr' was built under R version 3.3.3
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
mosaicplot(table(diamonds$cut, diamonds$color), main = "Diamonds: Cut vs Color",
xlab="Cut", ylab="Color")

ggplot(diamonds%>% group_by(cut)%>% mutate(AverageCarat=mean(carat)),aes(cut,price))+
geom_boxplot(aes(fill=AverageCarat), varwidth = TRUE)+
labs(title="Cut versus Price", subtitle="Width of boxplot proportional to sample
size of group", x="Cut", y="Price", fill="Average Carat")

ggplot(diamonds %>% group_by(color, cut) %>% mutate(averageprice=mean(price)), aes(x=cut, y=carat))+
geom_boxplot(aes(fill=averageprice,colour=color))+
labs(title="Cut versus Carat versus Price", x="Cut", y="Carat", fill="Average Price",
colour="Color")
