Source file ⇒ lab_5.Rmd
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
1. Is the data table glyph ready?
Yes, the data table is glyph ready as there are no variables that we do not need to do any data wrangling. The only variables that we will need are cut, price, and carat.
2.What are the glyphs?
In this case, the glyphs are the points and the smooth curves in the graph.
3. What are the aesthetics?
The aesthetics that are used in this plot are x-axis, y-axis, and color.
4. What are the scales?
Price is mapped to the y-axis, carat is mapped to the x-axis, and cut is mapped to color.
5. Are there fixed attributes?
The only fixed attributes are in the colors of the labels and plot title.
6. Are there labels and themes?
Labels:
Themes:
plot1 <- d %>%
ggplot(aes(x = Carat, y = Price)) +
#maps the Carat and Price to the x,y axes
geom_point(size = 3) +
#plots point glyphs with a size 3
geom_smooth(aes(col = cut, fill = cut)) +
#generates a loess smooth curve on top of the points
facet_wrap(~cut) +
#provides five different graphs separated by cut
labs(title = "Diamonds", x = "Carat", y = "Price") +
#creates a title and renames x,y labels properly
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 elements to match the color and size of the graphic given in the assignment
Here is the plot to be displayed: