ggplot(divorce_margarine, aes(x=margarine_consumption_per_capita, y=divorce_rate_maine))+geom_point()+geom_smooth(method ="lm", se =FALSE, color="pink" ) +labs(title="relationship between margarine consumption and divorce rate", x="maragrine consumption (pounds per capita)", y="Divorce Rate") +theme_dark()
`geom_smooth()` using formula = 'y ~ x'
Add a third variable and color :D
ggplot(divorce_margarine, aes(x= margarine_consumption_per_capita, y= divorce_rate_maine, color=as.factor(year))) +geom_point()+geom_smooth(method="lm", se =FALSE, color ="pink")+labs(title ="Relationship between margarine consumption and divorce rate",x="Maragrine consumption (pounds per capita)", y="Divorce Rate", color="Year")+theme_dark()
`geom_smooth()` using formula = 'y ~ x'
In my data visualization I generated a scatter plot, visualizing the relationship between maragine consumption per capita, and the divorce rate in Maine. The ggplot function creates the plot using the divorce_margarine’ data set. The code “aes” contains both the x-axis and y-axis. The ’geom_point, adds points representing each data point. I decided to add a line which is pink instead of red just because I found it more appealing . I used labs to state the plot title and axis labels and lastly I changed the theme from minimal to dark because I believe a dark background just makes the colors pop more. To wrap up my scatter plot I decided to add the variable year, which was the only variable left in my data set. I included it with my aes function of my ggplot assigning it to the color aesthetic. Making each year a different color so my coding can ensure that the variable year was treated as a categorical variable.