Skip to content

Instantly share code, notes, and snippets.

@jeffreyiacono
Last active July 18, 2016 03:10
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 jeffreyiacono/d51e0f94a53fe34124958c7d49b5d74d to your computer and use it in GitHub Desktop.
Save jeffreyiacono/d51e0f94a53fe34124958c7d49b5d74d to your computer and use it in GitHub Desktop.
Color-coded Start / End Plotting with R
library(ggplot2)
library(reshape2)
df <- data.frame(grp = 1:25, start = rnorm(25, 10, 5), end = rnorm(25, 5, 3))
df$end_higher <- df$start < df$end
mdf <- melt(df, id.vars = c("grp", "end_higher"))
names(mdf) <- c("grp", "end_higher", "category", "value")
mdf$grp <- factor(mdf$grp)
mdf$category <- factor(mdf$category)
mdf$end_higher <- factor(mdf$end_higher)
ggplot(mdf, aes(x = category, y = value, group = grp, color = end_higher)) + geom_point() + geom_line()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment