Trends, Correlations, and Scatter plots

You can study trends in data by looking at scatter plots of two variables. This can reveal whether one variable is related to another variable. If variable A increases as variable B increases, it is considered a positive correlation. If variable A decreases as variable B increases, it is considered a negative correlation. If there is no clear trend, then it is considered a zero correlation. The values of the correlation coefficient can be from -1 to +1.

To study whether there is a trend, you can add a trend line by fitting the points and studying the goodness of fit.

For example, we can add a linear regression line to a scatter plot. To do so, we will add stat_smooth() and tell it to use method=lm

Get Applied Data Visualization with R and ggplot2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.