Created
June 3, 2017 10:21
-
-
Save mhermans/867b5d2b7e8f8f8738c4fc3faa826889 to your computer and use it in GitHub Desktop.
R snippet: generate exaple trend data and fit loess smooth
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dplyr) | |
library(ggplot2) | |
set.seed(1234) | |
d.trend <- data.frame( | |
year = seq(as.Date("1911/1/1"), as.Date("2010/1/1"), "years"), | |
female = seq(1,100)*runif(100,0,1), | |
male = seq(1,100)*runif(100,0,1)) | |
d.trend$total = d.trend$male + d.trend$female | |
d.trend <- d.trend %>% | |
gather(gender, employed, male, female, total) | |
p.trend <- ggplot(d.trend, aes( | |
x = year, y = employed, | |
group = gender, color = gender)) | |
p.trend <- p.trend + xlim(c(as.Date("1911/1/1"), as.Date("2020/1/1"))) | |
p.trend <- p.trend + geom_point() + stat_smooth(method='lm', fullrange = TRUE) | |
p.trend |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment