# Don't forget to load the ggplot2 package library(ggplot2)
2024
# Don't forget to load the ggplot2 package library(ggplot2)
geom_point()
ggplot(data = mpg, aes(x = displ, y = hwy, color = class)) + geom_point()
geom_point()
geom_line
# Line Plot ggplot(data = mpg, aes(x = displ, y = hwy, color = class)) + geom_line()
geom_line
geom_smooth
# Scatter Plot with a Smooth Line ggplot(data = mpg, aes(x = displ, y = hwy, color = class)) + geom_point() + geom_smooth()
geom_smooth
geom_bar
# Bar Chart ggplot(data = mpg, aes(x = class, fill = class)) + geom_bar()
geom_bar
geom_boxplot
# Boxplot ggplot(data = mpg, aes(x = class, y = hwy, fill = class)) + geom_boxplot()
geom_boxplot
geom_violin
# Violin Plot ggplot(data = mpg, aes(x = class, y = hwy, fill = class)) + geom_violin()
geom_violin
geom_histogram
# Histogram ggplot(data = mpg, aes(x = hwy)) + geom_histogram()
geom_histogram
geom_density
# Density Plot ggplot(data = mpg, aes(x = hwy, fill = class)) + geom
geom_density
Add a smooth line to the following plot that summarizes the relationship between these two variables.
ggplot(data = mpg, aes(x = displ, y = hwy, color = class)) + geom_point()
ggplot(data = mpg, aes(x = displ, y = hwy, color = class)) + geom_point() + geom_smooth()
Modify the following code to create a histogram exploring the distribution of highway miles per gallon (hwy
) in the mpg
dataset. Adjust the number of bins to refine the histogram’s granularity.
ggplot(data = mpg, aes(x = hwy))
ggplot(data = mpg, aes(x = hwy)) + geom_histogram(bins=100)