Skip to content

Instantly share code, notes, and snippets.

@mhermans
Created June 3, 2017 10:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhermans/867b5d2b7e8f8f8738c4fc3faa826889 to your computer and use it in GitHub Desktop.
Save mhermans/867b5d2b7e8f8f8738c4fc3faa826889 to your computer and use it in GitHub Desktop.
R snippet: generate exaple trend data and fit loess smooth
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