In [1]:
library(ggplot2)

In [2]:
d1 = read.table("~/wt_data/bertha1-WT-ff14SB/myevecs_bertha1_backbonens.dat")
d2 = read.table("~/wt_data/guanine1-WT-ff14SB/myevecs_guanine1_backbonens.dat")
d3 = read.table("~/wt_data/parnassus1-WT-ff14SB/myevecs_parnassus1_backbonens.dat")
d4 = read.table("~/wt_data/parnassus2-WT-ff14SB/myevecs_parnassus2_backbonens.dat")
d5 = read.table("~/wt_data/spinoza2-WT-ff14SB/myevecs_spinoza2_backbonens.dat")
d6 = read.table("~/wt_data/sod1-WT-ff14SB/myevecs_sod1_backbonens.dat")
d7 = read.table("~/wt_data/run8/myevecs_run8_backbonens.dat")
d8 = read.table("~/wt_data/run9/myevecs_run9_backbonens.dat")
d9 = read.table("~/wt_data/run10/myevecs_run10_backbonens.dat")
d10 = read.table("~/wt_data/run11/myevecs_run11_backbonens.dat")

In [3]:
dfNew <- rbind(data.frame(d1, Group='run1'),
               data.frame(d2, Group='run2'),
               data.frame(d3, Group='run3'),
               data.frame(d4, Group='run4'),
               data.frame(d5, Group='run5'),
               data.frame(d6, Group='run6'),
               data.frame(d7, Group='run7'),
               data.frame(d8, Group='run8'),
               data.frame(d9, Group='run9'),
               data.frame(d10, Group='run10'))

In [4]:
pc1 <- ggplot(dfNew, aes(x=V2, color=Group)) +
  geom_line(stat='density', size=1.0) +
  theme_bw(15) +
  labs(x='PC1 (Å)', y='Density') +
  theme(legend.position='none')

pc2 <- ggplot(dfNew, aes(x=V3, color=Group)) +
  geom_line(stat='density', size=1.0) +
  theme_bw(15) +
  labs(x='PC2 (Å)', y='Density') +
  theme(legend.position='none')

pc3 <- ggplot(dfNew, aes(x=V4, color=Group)) +
  geom_line(stat='density', size=1.0) +
  theme_bw(15) +
  labs(x='PC3 (Å)', y='Density') +
  theme(legend.position='none')

pc4 <- ggplot(dfNew, aes(x=V5, color=Group)) +
  geom_line(stat='density', size=1.0) +
  theme_bw(15) +
  labs(x='PC4 (Å)', y='Density') +
  theme(legend.position='none')

pc5 <- ggplot(dfNew, aes(x=V6, color=Group)) +
  geom_line(stat='density', size=1.0) +
  theme_bw(15) +
  labs(x='PC5 (Å)', y='Density') +
  theme(legend.position='none')

pc6 <- ggplot(dfNew, aes(x=V7, color=Group)) +
  geom_line(stat='density', size=1.0) +
  theme_bw(15) +
  labs(x='PC6 (Å)', y='Density') +
  theme(legend.position='none')

pc7 <- ggplot(dfNew, aes(x=V8, color=Group)) +
  geom_line(stat='density', size=1.0) +
  theme_bw(15) +
  labs(x='PC7 (Å)', y='Density') +
  theme(legend.position='none')

pc8 <- ggplot(dfNew, aes(x=V9, color=Group)) +
  geom_line(stat='density', size=1.0) +
  theme_bw(15) +
  labs(x='PC8 (Å)', y='Density') +
  theme(legend.position='none')


pc9 <- ggplot(dfNew, aes(x=V10, color=Group)) +
  geom_line(stat='density', size=1.0) +
  theme_bw(15) +
  labs(x='PC9 (Å)', y='Density') +
  theme(legend.position='none')

In [5]:
multiplot <- function(..., plotlist=NULL, file, cols=1, layout=NULL) {
  library(grid)

  # Make a list from the ... arguments and plotlist
  plots <- c(list(...), plotlist)

  numPlots = length(plots)

  # If layout is NULL, then use 'cols' to determine layout
  if (is.null(layout)) {
    # Make the panel
    # ncol: Number of columns of plots
    # nrow: Number of rows needed, calculated from # of cols
    layout <- matrix(seq(1, cols * ceiling(numPlots/cols)),
                    ncol = cols, nrow = ceiling(numPlots/cols))
  }

 if (numPlots==1) {
    print(plots[[1]])

  } else {
    # Set up the page
    grid.newpage()
    pushViewport(viewport(layout = grid.layout(nrow(layout), ncol(layout))))

    # Make each plot, in the correct location
    for (i in 1:numPlots) {
      # Get the i,j matrix positions of the regions that contain this subplot
      matchidx <- as.data.frame(which(layout == i, arr.ind = TRUE))

      print(plots[[i]], vp = viewport(layout.pos.row = matchidx$row,
                                      layout.pos.col = matchidx$col))
    }
  }
}

In [6]:
multiplot(pc1, pc4, pc7, pc2, pc5, pc8, pc3, pc6, pc9, cols=3)



In [ ]: