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:
#PLOT 1
ggplot(mtcars, aes(x = wt, y = mpg)) +
geom_point(color = "black", fill = "white", size = 7, shape = 21, stroke = 1.5) +
labs(title = "Plot 1: MPG vs Weight",
x = "Weight represented in per 1000 lbs",
y = "Miles per Gallon abbreviated to: (mpg)") +
theme_classic() +
theme(
axis.text = element_text(size = 15, color = "lightgray"),
plot.title = element_text(size = 8, face = "bold")
) +
scale_x_continuous(breaks = seq(1, 6, by = 1), labels = seq(1000, 6000, by = 1000))
#PLOT 2
ggplot(mtcars, aes(x = wt, y = mpg)) +
geom_point(color = "hotpink", size = 3) +
labs(title = "Plot 2: MPG vs Weight", x = "Weight (1000 lbs)", y = "Miles per Gallon (mpg)") +
theme_minimal() +
theme(
panel.grid.major = element_line(color = "gray", size = 1.5),
panel.grid.minor = element_line(color = "gray", size = 1)
)
## Warning: The `size` argument of `element_line()` is deprecated as of ggplot2 3.4.0.
## ℹ Please use the `linewidth` argument instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
#PLOT 3
ggplot(mtcars, aes(x = wt, y = mpg)) +
geom_point(aes(color = factor(cyl), shape = factor(cyl)), size = 4, alpha = 0.5) +
scale_color_brewer(palette = "Set1") +
labs(title = "Plot 3: MPG vs Weight",
x = "Weight (1000 lbs)",
y = "Miles per Gallon (mpg)",
color = "Cylinders",
shape = "Cylinders") +
theme_dark() +
theme(
panel.grid.major = element_line(color = "black", size = 0.4),
panel.grid.minor = element_line(color = "black", size = 0.4),
axis.text = element_text(size = 7)
)
#PLOT 4 (BEST PLOT)
plot4 <- ggplot(mtcars, aes(x = wt, y = mpg)) +
geom_line(aes(group = cyl,
text = paste("Cylinders:", cyl,
"<br>Weight:", wt,
"<br>MPG:", mpg)),
color = "orange", linetype = "dashed") +
geom_point(aes(color = factor(cyl),
text = paste("Cylinders:", cyl,
"<br>Weight:", wt,
"<br>MPG:", mpg)),
size = 3) +
scale_color_manual(values = c("#B2182B", "#2166AC", "#4D9221")) +
labs(title = "Plot 4: MPG vs Weight",
x = "Weight (1000 lbs)",
y = "Miles per Gallon (mpg)",
color = "Cylinders") +
theme_bw() +
theme(
axis.text = element_text(size = 11)
)
## Warning in geom_line(aes(group = cyl, text = paste("Cylinders:", cyl,
## "<br>Weight:", : Ignoring unknown aesthetics: text
## Warning in geom_point(aes(color = factor(cyl), text = paste("Cylinders:", :
## Ignoring unknown aesthetics: text
ggplotly(plot4, tooltip = "text")
#In general, I think the best plot is “Plot 4”. This plot is clean, concise,
#and merely easy to interpret while simultaneously presenting all the critical information conveyed by the data. The axis/titles are short & simple. There is
#a legend which color codes the Cylinder types to show in the data. I made the
#points to a fitting size, as well as color coding them to muted but noticeable
#colors. With the “background” of the visualization I purposefully kept it as minimalist as possible, as I didn’t want background color and gridlines to draw attention from the interpretation of the data. I even included a dashed-trendline
#to show the general path/trend of the data. Additionally, I included hover-texts
#to make the visualization more interactive. I think this feature really emphasizes user convenience, as the viewer can just hover over a specific point to find the
#MPG and Weight.
#With my other graphs, they are just too straining on the eyes. Specifically
#“Plot 3,” this plot is taking away from the actual interpretation of the data.
#The dark gray background color and point transparency make the data 10 times
#more difficult to view. The size of the axis numerics are also incredibly small.
#Both “Plot 2 & 1” follow this same theme. The gridlines on “Plot 2” are
#obnoxiously loud making the visualization unappealing to even look at.
#Overall there are multiple different aesthetic properties demonstrated:
#Point Color, Point Shape, Point Size, Point Transparency, Point Borders,
#Gridline Color, Gridline Size, Title Font Size, Size of Numerical Axis
#Values, Background Theme, Color Pallet/Color Mapping, Legend Inclusion,
#Trendline Inclusion (Color changed aswell), and Hover Texts.