# load package and data
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.4.3
data(mpg, package="ggplot2") # alternate source: "http://goo.gl/uEeRGu")
theme_set(theme_bw()) # pre-set the bw theme.
g <- ggplot(mpg, aes(cyl, hwy))
# Scatterplot
g + geom_point() +
geom_smooth(method="lm", se=F) +
labs(subtitle="mpg: cyl vs highway mileage",
y="hwy",
x="cyl",
title="Scatterplot with overlapping points",
caption="Source: midwest")
## `geom_smooth()` using formula = 'y ~ x'

# load package and data
library(ggplot2)
data(mpg, package="ggplot2")
# mpg <- read.csv("http://goo.gl/uEeRGu")
# Scatterplot
theme_set(theme_bw()) # pre-set the bw theme.
g <- ggplot(mpg, aes(year, hwy))
g + geom_jitter(width = .5, size=1) +
labs(subtitle="mpg: year vs highway mileage",
y="hwy",
x="year",
title="Jittered Points")
