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.290 Premium   I     VS2      62.4    58   334  4.2   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
diamonds2 <- diamonds
"as.character(clarity)" <- as.character(diamonds2$clarity)
DiamondPlot1 <- ggplot(diamonds2, aes(carat,price))+
  geom_point(aes(color = as.character(clarity)),
             alpha = .3) + theme_bw() + xlab("Diamond Carats") + ylab("Diamond Price")
print(DiamondPlot1 + ggtitle("Scatterplot of Diamond Prices"))

DiamondPlot2 <- ggplot(diamonds2, aes(carat,price))+
  geom_point(aes(color = as.character(clarity)),
             alpha = .3) + theme_bw() + theme(legend.position = "none") + xlab("Diamond Carats") + ylab("Diamond Price") +facet_wrap(~clarity)
print(DiamondPlot2 + ggtitle("Scatterplot of Diamond Prices"))

ggplot(diamonds2, aes(table,price))+
  geom_smooth(method = "lm",  linetype = "dashed", color = "red",) +
 theme_bw() + xlab("Table") + ylab("Price")

ggplot(diamonds2, aes(depth,price))+
  geom_smooth(method = "lm",  linetype = "dotdash", color = "white",) +
 theme_bw() + xlab("Depth") + ylab("Price")

ggplot(diamonds2, aes(price)) +
  geom_histogram(binwidth = 3) +
  ylim(NA,130) +theme_bw()
## Warning: Removed 18 rows containing missing values (geom_bar).

ggplot(diamonds2, aes(price)) +
  geom_histogram() +
 theme_bw()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

ggplot(diamonds2, aes(clarity)) +
  geom_bar(aes(color = clarity, fill= clarity)) +
 theme_bw()+ theme(legend.position = "none")

ggplot(diamonds2, aes(cut,depth )) +
  geom_violin(fill = "white", color = "#3366FF") +
  geom_jitter(color = "red", alpha = .05) +
 theme_bw()

ggplot(diamonds2, aes(x,price))+
  geom_smooth(method = "lm", color = "green")+
  geom_smooth(color = "blue", se = FALSE)+
 theme_bw() + xlab("x") + ylab("Price") 
## `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'