R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00

Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.

For this Base R gragh We are investigating the relationship between carat (weight of the diamond) and price to understand how the price of diamonds varies with their weight.

diamonds_dataset <- read.csv("diamonds.csv")
str(diamonds_dataset)
## 'data.frame':    53940 obs. of  10 variables:
##  $ carat  : num  0.23 0.21 0.23 0.29 0.31 0.24 0.24 0.26 0.22 0.23 ...
##  $ cut    : chr  "Ideal" "Premium" "Good" "Premium" ...
##  $ color  : chr  "E" "E" "E" "I" ...
##  $ clarity: chr  "SI2" "SI1" "VS1" "VS2" ...
##  $ depth  : num  61.5 59.8 56.9 62.4 63.3 62.8 62.3 61.9 65.1 59.4 ...
##  $ table  : num  55 61 65 58 58 57 57 55 61 61 ...
##  $ price  : int  326 326 327 334 335 336 336 337 337 338 ...
##  $ x      : num  3.95 3.89 4.05 4.2 4.34 3.94 3.95 4.07 3.87 4 ...
##  $ y      : num  3.98 3.84 4.07 4.23 4.35 3.96 3.98 4.11 3.78 4.05 ...
##  $ z      : num  2.43 2.31 2.31 2.63 2.75 2.48 2.47 2.53 2.49 2.39 ...
getwd()
## [1] "C:/Users/laure/Downloads/Data Visualization"
plot(diamonds_dataset$carat, diamonds_dataset$price, 
     xlab = "Carat", 
     ylab = "Price (USD)", 
     main = "Relationship between Carat and Price",
     col = "skyblue", pch = 16, cex = 0.8)

The above scatter plot of carat against price indicates a positive relationship between the two variables. As the carat of the diamond increases, the weight of the diamond increases. This observation is in line with the general practice in the diamond industry. However, there is some variability in price within each carat weight category, indicating that other factors such as cut, color, and clarity may also play a role in determining the price of diamonds. The scatter plot effectively captures the relationship between carat and price, providing valuable insights into the pricing dynamics of diamonds.

For this ggplot graph, We are investigating the relationship between depth and price of diamond to understand how the depth of diamonds affects their prices.

library(ggplot2)

diamonds_dataset <- read.csv("diamonds.csv")
str(diamonds_dataset)
## 'data.frame':    53940 obs. of  10 variables:
##  $ carat  : num  0.23 0.21 0.23 0.29 0.31 0.24 0.24 0.26 0.22 0.23 ...
##  $ cut    : chr  "Ideal" "Premium" "Good" "Premium" ...
##  $ color  : chr  "E" "E" "E" "I" ...
##  $ clarity: chr  "SI2" "SI1" "VS1" "VS2" ...
##  $ depth  : num  61.5 59.8 56.9 62.4 63.3 62.8 62.3 61.9 65.1 59.4 ...
##  $ table  : num  55 61 65 58 58 57 57 55 61 61 ...
##  $ price  : int  326 326 327 334 335 336 336 337 337 338 ...
##  $ x      : num  3.95 3.89 4.05 4.2 4.34 3.94 3.95 4.07 3.87 4 ...
##  $ y      : num  3.98 3.84 4.07 4.23 4.35 3.96 3.98 4.11 3.78 4.05 ...
##  $ z      : num  2.43 2.31 2.31 2.63 2.75 2.48 2.47 2.53 2.49 2.39 ...
ggplot(diamonds_dataset, aes(x = depth, y = price)) +
  geom_point(alpha = 0.3, color = "skyblue") +
  labs(x = "Depth",
       y = "Price (USD)", 
       title = "Relationship between Depth and Price of diamonds")

The graph above shows relationship between depth and price of diamonds. While there is come variability in price within each depth category,from the diamonds_dataset there seem to be no clear trend between depth and price of diamonds. This suggest that depth alone may not be s strong determinant of diamond prices, but other factors may play a more significant role.

For this plotly graph we are investigating the relationship between the quality of the diamond cut and its price to understand how cut quality influences diamond pricing. By visualizing the relationship using a scatter plot, with cut on the x-axis and price on the y-axis, we aim to identify any patterns or trends in diamond pricing based on cut quality.

library(ggplot2)
library(plotly)
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
library(dplyr)
## 
## 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
diamonds_dataset <- read.csv("diamonds.csv")



plot_ly(data = diamonds_dataset, x = ~cut, y = ~price, 
        type = "scatter", 
        mode = "markers",
        marker = list(color = ~carat, colorscale = 'Viridis'), 
        text = ~paste("Carat: ", carat)) %>%
  layout(xaxis = list(title = "Cut"), 
         yaxis = list(title = "Price (USD)"), 
         title = "Relationship between Cut and Price")

The scatter plot above shows the relationship between the quality of the diamond cut and its price. From the scatter plot, we can observe how different cut categories are distributed across various price ranges. Diamonds with higher cut quality, such as “Ideal” and “Premium,” tend to have higher prices, as indicated by the clustering of points towards the higher end of the price axis. Conversely, diamonds with lower cut quality, such as “Fair,” exhibit lower prices, with points clustered towards the lower end of the price axis. This graph discover patterns in diamond pricing based on cut quality, enabling informed decision-making in diamond selection and pricing strategies.