Created
March 2, 2014 15:36
-
-
Save piroyoung/9308306 to your computer and use it in GitHub Desktop.
plotting by ggplot
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(ggplot2) | |
library(reshape2) | |
setwd("~/work/R/ggplot2") | |
T <- 300 | |
N <- 8 | |
bm <- rnorm(T*N) | |
bm <- matrix(bm,nrow = T, ncol= N) | |
bm <- apply(bm, 2, cumsum) | |
bm <- bm + 20 | |
bmDataframe <- data.frame( | |
T = 1:T, | |
L1 = bm[,1], | |
L2 = bm[,2], | |
L3 = bm[,3], | |
L4 = bm[,4], | |
L5 = bm[,5], | |
L6 = bm[,6], | |
L7 = bm[,7], | |
L8 = bm[,8] | |
) | |
bmDataframe <- melt(bmDataframe, | |
id = 'T', | |
measure = c('L1','L2','L3','L4','L5','L6','L7','L8') | |
) | |
gp = ggplot(bmDataframe, | |
aes(x = T, | |
y = value, | |
group = variable, | |
colour = variable, | |
fill = variable | |
) | |
) | |
gp = gp + geom_area() | |
print(gp) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment