Skip to content

Instantly share code, notes, and snippets.

@TysonStanley
Last active December 23, 2016 00:11
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 TysonStanley/be362622eb26ef066e47fb84ec1fe712 to your computer and use it in GitHub Desktop.
Save TysonStanley/be362622eb26ef066e47fb84ec1fe712 to your computer and use it in GitHub Desktop.
## Code for Example Plot for @evergreendata
## Tyson S. Barrett
## Data
x_num = c(4.2, 4.5, 4, 4.5, 3.9, 3.6)
year = c(2011:2016)
x_per = c(.52, .58, .6, .63, .64, .67)
df = data.frame(x_num, year, x_per)
## Libraries and Plots
library(ggplot2)
library(ggrepel)
library(anteo) ## available on github via "tysonstanley/anteo"
ggplot(df, aes(x_per, x_num, label = year)) +
geom_point(color = "dodgerblue4", alpha = .8) +
geom_smooth(method = "lm",
se=FALSE,
color = "coral3") +
geom_text_repel(nudge_y = .05,
segment.alpha = .5,
color = "dodgerblue4") +
coord_cartesian(ylim=c(3,5)) +
labs(y = "# of referrals per 1,000 students per day",
x = "% of students at or above benchmark",
title = "Relationship between Referrals and Students at or Above Benchmark",
subtitle = "Example using a Linear Regression line") +
theme_anteo_wh()
ggplot(df, aes(x_per, x_num, label = year)) +
geom_point(color = "dodgerblue4", alpha = .8) +
geom_smooth(method = "lm",
formula = y ~ poly(x,2),
se=FALSE,
color = "coral3") +
geom_text_repel(nudge_y = .05,
segment.alpha = .5,
color = "dodgerblue4") +
coord_cartesian(ylim=c(3,5)) +
labs(y = "# of referrals per 1,000 students per day",
x = "% of students at or above benchmark",
title = "Relationship between Referrals and Students at or Above Benchmark",
subtitle = "Example using a Linear Regression line") +
theme_anteo_wh()
df$x_per = df$x_per * 100
df_long = gather(df, "var", "value", c(1,3))
df_long$var = factor(df_long$var, labels = c("Referrals per Day", "Percentage at Benchmark"))
ggplot(df_long, aes(year, value)) +
geom_point(color = "dodgerblue4", alpha = .8) +
geom_line(color = "dodgerblue4", size=1) +
labs(y = "",
x = "Year") +
theme_anteo_wh() +
facet_wrap(~var, scales = "free")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment