geom_point() adds point layers to ggplot2 graphics, producing correlation plots—also called scatterplots—from two mapped numeric variables. Use size = 3 to draw points three times their default size. section 4.5.3 section 14.4.1
A typical correlation plot combines geom_point() with:
- ggplot() mappings that place one variable on the x-axis and another on the y-axis. section 4.5.3 section 14.4.1
- geom_smooth(method = lm, se = FALSE) to add a linear regression line without its default confidence interval. section 4.5.3 section 14.4.1
- Labels and scales that identify the variables, correlation coefficient, and axis formatting. section 4.5.3
p7 <- ggplot(free_agents, aes(x = annual_salary, y = win_shares)) +
geom_point(size = 3) +
labs(title = "Annual Salaries vs. Win Shares",
subtitle = "correlation coefficient = 0.76",
x = "Annual Salaries",
y = "Win Shares") +
geom_smooth(method = lm, se = FALSE) +
scale_x_continuous(label = scales::comma) +
theme(plot.title = element_text(face = "bold"))
print(p7)
Run this complete NBA example to plot annual salaries against win shares with enlarged points, labels, a regression line, and formatted salaries. section 4.5.3
