⇒ /Users/sambamamba/Desktop/Stat_133/Stat_133 Stuff/Lab 5 .Rmd

Please make the following plot using the data table d given below. I have provided examples to help you.

Questions to ask yourself to get started:

Is the data table glyph ready? If not, do I need to need to convert table formats (i.e. narrow to wide) or join another table?

Loosely speaking, the data table is glyph-ready, since we have all the column variables available to be mapped each to their own respective graphical attribute.

More specifically:

In other words, no data-wrangling was necessary to map the variables to the graph. Although technically, there is one minor detail that requires wrangling in order to make the variables specifically match the graph, which is using the rename() function to capitalize the axis titles on the x- and y- axes.

What are the glyphs? The glyphs are the points on the graph and the smooth curve fitted on top of the points.

What are the aesthetics? The aesthetics are the x- and y- axes and color.

What are the scales (i.e. mappings) The scales are:

Are there fixed attributes (i.e. col = “red”)?

The fixed attributes for this graph are:

Are there labels and themes?

Labels:

Themes:

Plot:

Below is the data set given in the assignment:

set.seed(123)
d <- diamonds[sample(nrow(diamonds), 1000), ] %>%
  rename(Carat = carat, Price = price)
head(d)
## Source: local data frame [6 x 10]
## 
##   Carat       cut  color clarity depth table Price     x     y     z
##   (dbl)    (fctr) (fctr)  (fctr) (dbl) (dbl) (int) (dbl) (dbl) (dbl)
## 1  1.03   Premium      G     VS2  62.3    59  6214  6.38  6.42  3.99
## 2  0.50      Fair      D     SI1  65.7    56  1323  5.01  4.97  3.28
## 3  1.74 Very Good      H     SI2  62.1    59 10086  7.65  7.78  4.79
## 4  0.51     Ideal      D     VS2  61.2    55  1882  5.18  5.16  3.16
## 5  0.70     Ideal      H     SI1  62.5    56  2294  5.64  5.69  3.54
## 6  0.71     Ideal      H      IF  62.0    54  3190  5.71  5.75  3.55

Below is the step-by-step syntax delineating each aspect of the graph:

d1 <- d %>%
  ggplot( aes(x = Carat, y = Price)) + #maps the Carat and Price aesthetics to the x-y axes
  geom_point(size = 3) + #maps the point glyphs onto the graph with a size 3
  geom_smooth(aes(col = cut, fill = cut)) +  #generates a loess smooth curve overlaying the data points, distinguishable by color/cut
  facet_wrap(~cut) + #provides five different graphs for better comparison of data
  labs(title = "Diamonds", x = "Carat", y = "Price") + #creates a plot title and ensures x and y axes have the axes titles Carat and Price
  theme(plot.title = element_text(size = 25, color = "blue"), axis.text.y = element_text(color = "red", size = 10), axis.text.x = element_blank(), axis.title.x = element_text(color = "red", size = 15), axis.title = element_text(color = "red", size = 15)) #formats non-data visual elements to match the color and size of the graphic given in the assignment page
d1