Introduction

0.1 Set work directory

setwd("~/gitbook")

0.2 Load the data

data <-read.table("box_plots_mtcars.txt",header=T,sep="\t")
df <- data[, c("mpg", "cyl", "wt")]

df2 <-read.table("histogram_plots.txt",header=T,sep="\t")

df3 <- read.table("volcano_plots.txt", header=TRUE)

df4 <- read.table("manhattan_plots_gwasResults.txt",header=T,sep="\t")

df5 <-read.table("heatmaps.txt",header=T,sep="\t")
dm <- data.matrix(df5[1:nrow(df5),2:ncol(df5)])
row.names(dm) <- df5[,1]

df6 <- read.table("ballon_plots_GO.txt", header=T, sep="\t")

df7 <- read.table("box_plots_David_GO.txt",header=T,sep="\t")
df7 <- df7[1:10,]

0.3 Install and library packages

install.packages("ggplot2")
library(ggplot2)
install.packages("qqman")
library(qqman)
install.packages("gplots")
library(gplots)
install.packages("pheatmap")
library(pheatmap)
install.packages("scales")
library(scales)
install.packages("reshape2")
library(reshape2)
install.packages("RColorBrewer")
library(RColorBrewer)
install.packages("plyr")
library(plyr)
install.packages("plotrix")
library(plotrix)

0.4. Save the plot

If you want to save the plot, please use "pdf(), dev.off()" or "ggsave()". The second one is specific for the ggplot2 package.

For example,

pdf("1.1.Basic_boxplot.pdf", height = 3, width = 3)
ggplot(df, aes(x=cyl, y=mpg)) + 
  geom_boxplot(fill="gray")+
  labs(title="Plot of mpg per cyl",x="Cyl", y = "Mpg")+
  theme_classic()
dev.off()
#Or 
p <- ggplot(df, aes(x=cyl, y=mpg)) + 
  geom_boxplot(fill="gray")+
  labs(title="Plot of mpg per cyl",x="Cyl", y = "Mpg")+
  theme_classic()
ggsave("1.1.Basic_boxplot.pdf", plot=p, height = 3, width = 3)

Last updated