Let’s look at the diamonds dataset present in the ggplot2 pacakge. Since our dataset is part of the ggplot2 package, we can use the help() function to know more about the dataset.
help("diamonds")
According to the documentation, diamonds dataset contains the prices and other attributes of almost 54,000 diamonds. The variables/columns are as follows:
price price in US dollars ($326–$18,823)
carat weight of the diamond (0.2–5.01)
cut quality of the cut (Fair, Good, Very Good, Premium, Ideal)
color diamond colour, from D (best) to J (worst)
clarity a measurement of how clear the diamond is (I1 (worst), SI2, SI1, VS2, VS1, VVS2, VVS1, IF (best))
x length in mm (0–10.74)
y width in mm (0–58.9)
z depth in mm (0–31.8)
depth total depth percentage = z / mean(x, y) = 2 * z / (x + y) (43–79)
table width of top of diamond relative to widest point (43–95)
#load the dataset
data("diamonds")
Now that we have succesfully loaded our data, let’s take a look at the dataset. We can use the glimpse() function to get a brief idea of the data that we are dealing with.
glimpse(diamonds)
## Rows: 53,940
## Columns: 10
## $ carat <dbl> 0.23, 0.21, 0.23, 0.29, 0.31, 0.24, 0.24, 0.26, 0.22, 0.23, 0.…
## $ cut <ord> Ideal, Premium, Good, Premium, Good, Very Good, Very Good, Ver…
## $ color <ord> E, E, E, I, J, J, I, H, E, H, J, J, F, J, E, E, I, J, J, J, I,…
## $ clarity <ord> SI2, SI1, VS1, VS2, SI2, VVS2, VVS1, SI1, VS2, VS1, SI1, VS1, …
## $ depth <dbl> 61.5, 59.8, 56.9, 62.4, 63.3, 62.8, 62.3, 61.9, 65.1, 59.4, 64…
## $ table <dbl> 55, 61, 65, 58, 58, 57, 57, 55, 61, 61, 55, 56, 61, 54, 62, 58…
## $ price <int> 326, 326, 327, 334, 335, 336, 336, 337, 337, 338, 339, 340, 34…
## $ x <dbl> 3.95, 3.89, 4.05, 4.20, 4.34, 3.94, 3.95, 4.07, 3.87, 4.00, 4.…
## $ y <dbl> 3.98, 3.84, 4.07, 4.23, 4.35, 3.96, 3.98, 4.11, 3.78, 4.05, 4.…
## $ z <dbl> 2.43, 2.31, 2.31, 2.63, 2.75, 2.48, 2.47, 2.53, 2.49, 2.39, 2.…
As we can see, the dataset diamonds has 53,940 rows and 10 columns. From a brief glimpse at the dataset, we can get an idea about most of the variables/columns in the dataset.
Without the documentation, we wouldn’t the range scale of any of the columns in the dataset. The documentation clearly gives the range and scale for all the variables including both numnerical and categorical columns.
There are a few columns such as x, y and z, which tell the length, width and depth of the diamonds. We wouldn’t know this information unless we looked at the documentation of the diamonds dataset as the column names are very vague. Also, it would be very difficult to know the metrics used for these various measurements without the help of the documentation.
Also, the diamonds dataset has a column called ‘depth’ which calculates the total depth percentage based on the x, y, z values. We wouldn’t know without the help of the documentation. The documentation clearly explains how the depth variable is calculated, along with the formula and the variables used.
Thanks to the well-detailed and informative documentation of the diamonds dataset, most of the attributes and values are clear after reading the documentation. The user can easily understand and interpret all the columns in the data with the help of the documentation.
As mentioned in Task 2, we don’t have any unclear columns in the dataset thanks to the well-detailed and informative documentation of the diamonds dataset.
But there are a few anamolies in the dataset that I’d like to point out. According to the documentation, the ‘x’, ‘y’ and ‘z’ columns have a min of 0 range but dimensions can’t be 0. A value of ‘0’ could indicate data entry errors or placeholders for missing data. Let’s plot a graph for the ‘x’, ‘y’ and ‘z’ columns concerning these anamolies.
# Plot for x dimension
ggplot(diamonds, aes(x=x, y=price, color=(x <= 0))) +
geom_point(alpha=0.5) +
scale_color_manual(values=c("blue", "red"), name="Anomalous Values", labels=c("Valid", "Anomalous")) +
ggtitle("Price vs. X Dimension") +
xlab("X Dimension") +
ylab("Price ($)") +
theme(legend.position="top")
# Plot for y dimension
ggplot(diamonds, aes(x=y, y=price, color=(y <= 0))) +
geom_point(alpha=0.5) +
scale_color_manual(values=c("blue", "red"), name="Anomalous Values", labels=c("Valid", "Anomalous")) +
ggtitle("Price vs. Y Dimension") +
xlab("Y Dimension") +
ylab("Price ($)") +
theme(legend.position="top")
# Plot for z dimension
ggplot(diamonds, aes(x=z, y=price, color=(z <= 0))) +
geom_point(alpha=0.5) +
scale_color_manual(values=c("blue", "red"), name="Anomalous Values", labels=c("Valid", "Anomalous")) +
ggtitle("Price vs. Z Dimension") +
xlab("Z Dimension") +
ylab("Price ($)") +
theme(legend.position="top")
Dimensions are fundamental for understanding a diamond’s size and shape. Anomalous values can lead to incorrect analyses, especially if used in modeling or other calculations.
Few possible solutions could be to conduct a thorough exploratory data analysis (EDA) to identify such anomalies, address anomalies either by removing them or by appropriate imputation, or document the data cleaning and preprocessing steps for transparency.
Further, we need to assess Why do these anomalous values exist in the dataset? Are there other columns with similar anomalies? And how should these anomalies be treated – removal or imputation?