Draft

ggplot2 visualizations with the Diamonds Data set

Make a Subset of the Data

diamonds2 <- diamonds %>% filter(color %in% c("D","E","F"))

diamonds.report <- diamonds2 %>% 
  group_by(cut,color)  %>% 
  summarize(mean.depth = mean(depth)) 
## `summarise()` has grouped output by 'cut'. You can override using the `.groups` argument.
diamonds.report 
## # A tibble: 15 x 3
## # Groups:   cut [5]
##    cut       color mean.depth
##    <ord>     <ord>      <dbl>
##  1 Fair      D           64.0
##  2 Fair      E           63.3
##  3 Fair      F           63.5
##  4 Good      D           62.4
##  5 Good      E           62.2
##  6 Good      F           62.2
##  7 Very Good D           61.8
##  8 Very Good E           61.7
##  9 Very Good F           61.7
## 10 Premium   D           61.2
## 11 Premium   E           61.2
## 12 Premium   F           61.3
## 13 Ideal     D           61.7
## 14 Ideal     E           61.7
## 15 Ideal     F           61.7
p <- ggplot(data=diamonds.report, 
       aes(x = cut,
           y = mean.depth, 
           fill = color)) 
p+ geom_bar(stat="identity",position = "dodge") + 
         scale_fill_brewer(palette = "Greens" , direction = -1) +
         ggtitle("Diamonds") + 
         ylab("Mean Depth") + 
         theme_bw() +
         theme(axis.title.x = element_text(color="black", size=14, face="bold"),
               axis.title.y = element_text(color="black", size=14, face="bold"))

 p+ geom_bar(stat="identity",position = "stack") + 
         scale_fill_brewer(palette = "Greens" , direction = -1) +
         ggtitle("Diamonds") + 
         ylab("Mean Depth") + 
         theme_bw() +
         theme(axis.title.x = element_text(color="black", size=14, face="bold"),
               axis.title.y = element_text(color="black", size=14, face="bold"))