Data Visualization with ggplot
October 25, 2024
\[ \begin{align} (\text{Total Percentage Grade}) =&\;\, 0.05\times(\text{Attendance}) \notag\\ &\,+\, 0.15\times(\text{Quiz & Class Participation})\notag\\ & \,+\, 0.15\times(\text{Homework})\notag\\ &\,+\, 0.15\times(\text{Presentation})\notag\\ & \,+\, 0.50\times(\text{Exam}).\notag \end{align} \]
You are allowed up to 6 absences without penalty.
For each absence beyond the initial six, there will be a deduction of 1% from the Total Percentage Grade.
The single lowest homework score will be dropped when calculating the total homework score.
\[ \begin{align} &(\text{Total Exam Score}) \\ =\, &\text{max}\,\left\{0.50\times(\text{Midterm Exam Score}) \,+\, 0.50\times(\text{Final Exam Score})\right.,\notag\\ &\qquad\;\,\left.0.25\times(\text{Midterm Exam Score}) \,+\, 0.75\times(\text{Final Exam Score})\right\}.\notag \end{align} \]
\[ \begin{align} &(\text{Total Midterm Exam}) \\ =\, &\text{max}\,\left\{0.50\times(\text{Midterm Exam 1}) \,+\, 0.50\times(\text{Midterm Exam 2})\right.,\notag\\ &\qquad\;\,\left.0.25\times(\text{Midterm Exam 1}) \,+\, 0.75\times(\text{Midterm Exam 2})\right\}.\notag \end{align} \]
ggplot
The mpg
data frame, provided by ggplot2
, contains observations collected by the US Environmental Protection Agency on 38 models of car.
Q. Do cars with big engines use more fuel than cars with small engines?
displ
: a car’s engine size, in liters.hwy
: a car’s fuel efficiency on the highway, in miles per gallon (mpg).What does the relationship between engine size and fuel efficiency look like?
ggplot
mpg
, run the above code to put displ
on the x
-axis and hwy
on the y
-axis.A ggplot
graphic is a mapping
of variables in data
to aes
thetic attributes of geom
etric objects.
Three Essential Components in ggplot()
Graphics:
data
: data.frame containing the variables of interest.geom_*()
: geometric object in the plot (e.g., point, line, bar, histogram, boxplot).aes()
: aesthetic attributes of the geometric object (e.g., x
-axis, y
-axis, color
, shape
, size
, fill
) mapped to variables in the data.frame.ggplot
ggplot()
:
data = mpg
geom_point()
aes(x = displ, y = hwy)