Investigation Statement: With this data, I am trying to investigate the relationship between the size of the carat in diamonds and the price of the diamond. I chose to use a scatter plot for this investigation because scatter plots are able to show the strength of the relationship between the two variables. If the data shows an upward pattern, there is a positive relationship whereas if the data shows a downward pattern, there is a negative relationship.
diamonds <- read.csv("diamonds.csv")
plot(diamonds$carat, diamonds$price,
col = "blue",
main = "Effect of Carat Size on Diamond Price",
xlab = "Carat Size",
ylab = "Price")
Discussion: This plot is representing the relationship between the carat size of a diamond and the cost of the diamond. The x-axis is the carat size and the y-axis is the cost. When the carat size is either small or large, there is a positive relationship between carat size and cost in that when the carat size is small, the price is lower, and when the carat size is large, the price is higher. However, when the carat is medium size, there is more variation in price. When analyzing the strength of the relationship between carat size and price, there is an overall positive relationship since the points on the graph generally go in an upward direction.
Investigation Statement: With this data, I am trying to investigate whether a certain type of wine, red or white, has a higher alcohol content than the other. I chose to use a box plot because they are useful when comparing data between multiple groups. In this example, we would be comparing the alcohol content in red and white wine. Within the boxes, you can see the median value and the upper and lower quartile values for each group.
library(ggplot2)
wine <- read.csv("winequality.csv")
ggplot(wine, aes(x = type, y = alcohol)) + geom_boxplot() + labs(title="Concentration of Alcohol in Types of Wine", y="Alcohol Content")
Discussion: This plot is representing the alcohol content of red and white wines. The x-axis is the type of wine and the y-axis is the alcohol content. The median alcohol content of white wine is slightly higher than that of red wine. The range between the upper and lower quartiles is larger for white wine as well compared to red wine. This tells us that the alcohol content of red wines falls into a smaller range unlike white wines. Red wine also has some outliers in the data represented by the three dots above the box.
Investigation Statement: With this data, I am trying to investigate the relationship between a mother’s IQ and her child’s IQ. I chose to use a plot_ly scatter plot because a scatter plot will show the strength of the relationship between the mother and child’s IQ and by using plot_ly, I can investigate a third variable, such as the mother’s age when she had the child. If there is an upward trend, there is a positive relationship, and if there is a downward trend, there is a negative relationship between the variables.
library(plotly)
library(dslabs)
library(ggplot2)
library(tidyverse)
iq <- read.csv("kid_iq.csv")
iq %>%
plot_ly(x = ~mom_iq, y = ~kid_score, hoverinfo = "text", text = ~mom_age) %>%
add_markers(color = ~mom_age) %>%
layout(xaxis = list(title = "Mother's IQ"),
yaxis = list(title = "Child's IQ"),
title = "Effect of Mother's IQ on Child's IQ")
Discussion: This plot is representing the relationship between a mother’s IQ and her child’s IQ. The x-axis is the mother’s IQ and the y-axis is the child’s IQ. Each point representing a mother shows her age when she had her child when it is hovered over and the color gradient shows the color that corresponds to the age. There is a lot of variation with this data. There are some points where there is a positive relationship between the mother and child where they share similar IQ scores, but there are also points that don’t follow an upward trend. However, even if a mother has a lower IQ, her child is still more likely to have a higher IQ than her as opposed to a lower IQ. Age did not seem to have an effect on the relationship between a mother and child’s IQs.
Investigation Statement: With this data, I am trying to investigate the relationship between a state’s population and their cancer rate. I chose to use a plot_ly scatter plot because a scatter plot will show the strength of the relationship between cancer rates and population. By using plot_ly, I can add a hover feature to show the state that corresponds to each point to see which states have high or low cancer rates. If there is an upward trend, there is a positive relationship between cancer rates and population, and if there is a downward trend, there is a negative relationship.
library(plotly)
library(dslabs)
library(ggplot2)
library(tidyverse)
cancer <- read.csv("cancer.csv")
cancer %>%
plot_ly(x = ~Total.Population, y = ~Total.Rate, hoverinfo = "text", text = ~State) %>%
add_markers(color = ~State) %>%
layout(xaxis = list(title = "Population"),
yaxis = list(title = "Cancer Rate"),
title = "Cancer Rate in US 2007-2013")
Discussion: This plot is representing the relationship between US state populations and their cancer rates. The x-axis is the state population and the y-axis is the cancer rate. Each state is represented by a different color as seen on the right side of the plot. When looking at this plot, there is not a trend that the data is following. There is a wide range of cancer rates for states that have similar populations. However, the two states with the largest populations do have smaller cancer rates compared to the rest of the states. West Virginia is the state with the highest cancer rate and Utah was the state with the lowest. A future study could be done to investigate other factors that could cause higher cancer rates such as healthcare and lifestyle factors.