ggplot(df, aes(x = height, y = weight)) + geom_point()
Scatter plot
geom_line() / geom_col() / geom_histogram()
Line, bar, histogram
aes(colour = group)
Map a variable to colour
labs(title = "...", x = "...", y = "...")
Titles and axis labels
ggsave("plot.png", width = 6, height = 4)
Save the last plot
Statistics
mean(x, na.rm = TRUE) / median(x) / sd(x)
Centre and spread
table(x) / quantile(x)
Counts / quantiles
cor(x, y)
Correlation
model <- lm(y ~ x, data = df); summary(model)
Linear regression
t.test(x, y)
Two-sample t-test
Cookies & your privacy
We use essential cookies to keep this site working and secure.
With your permission, we'd also like to use Google Analytics cookies to understand site traffic.
We don't use advertising or social media tracking cookies, and we honor Global Privacy Control (GPC) browser signals.
Learn more in our Privacy Policy.
Your browser is sending a GPC signal, so analytics stays off even if you accept.