PATH30004

reads status

Step 1 install packages – dplyr and ggplot

packages <- c("dplyr", "ggplot2")
for (p in packages){
  if (!p %in% installed.packages()){
  install.packages(p, dependencies=T)
  }
  if (!p %in% .packages()){
  library(p, character.only=T)
  }
}

read the table

Step 2 read the stats table into dataframe

df <- read.csv("/Users/jianszhang/Documents/Coin/R/PATH300004_example.csv")
print(df)
      SAMPLE Reads      TYPE
1  barcode01  1000    ferret
2  barcode02  1500    ferret
3  barcode03  3000    ferret
4  barcode01   200 Influenza
5  barcode02   100 Influenza
6  barcode03   250 Influenza
7  barcode01    20     joint
8  barcode02     0     joint
9  barcode03   100     joint
10 barcode01   200  unmapped
11 barcode02   180  unmapped
12 barcode03  1000  unmapped

Make plots

Step 3 make barplot with ggplot2

ggplot(data=df, aes(x=SAMPLE, y=Reads, fill=TYPE)) +
  geom_bar(position="stack", stat="identity")

adjust plot parameters

Step 4 change parameters in ggplots

ggplot(data=df, aes(x=SAMPLE, y=Reads, fill=TYPE)) +
  geom_bar(position="fill", stat="identity")


ggplot(data=df, aes(x=SAMPLE, y=Reads, fill=TYPE)) +
  geom_bar(position="dodge", stat="identity")