Skip to content

Instantly share code, notes, and snippets.

@aivuk
Last active December 16, 2015 23:47
Show Gist options
  • Save aivuk/23009ec241837593fa4f to your computer and use it in GitHub Desktop.
Save aivuk/23009ec241837593fa4f to your computer and use it in GitHub Desktop.
library(plyr)
library(ggplot2)
x <- data.frame(a=runif(100,0,1),b=runif(100,0,1),c=runif(100,0,1),d=runif(100,0,1))
y <- data.frame(a=runif(5,0,1),b=runif(5,0,1),c=runif(5,0,1),d=runif(5,0,1))
df <- rbind(x,y)
df['idx'] <- seq(1,nrow(df))
mdf <- melt(df, id.vars = 'idx')
colors <- c(laply(seq(0, 1, 1/(nrow(x) - 1)), function(x) rgb(0,0,0,x)), rep('#FF0000', nrow(y)))
mdf['color'] <- rep(colors, length(x))
ggplot(data=mdf, aes(x=variable, y=value, group=idx, colour=color)) + geom_line() + scale_color_identity()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment