mirror of
https://github.com/gladstone-institutes/Bioinformatics-Workshops.git
synced 2025-11-30 09:45:43 -08:00
Updated intermediate R data visualization materials
This commit is contained in:
parent
08be3b61c3
commit
0eb7b8b40d
16 changed files with 584 additions and 0 deletions
41
intermediate-r-data-visualization/2. nucleotide_resolution.R
Normal file
41
intermediate-r-data-visualization/2. nucleotide_resolution.R
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
library(ggplot2)
|
||||
|
||||
#Following library will be used to reformat data for plotting.
|
||||
library(reshape2)
|
||||
|
||||
#Load the data for plotting.
|
||||
load("nucleotide_resolution.RData")
|
||||
|
||||
#Open a pdf file for plotting.
|
||||
pdf("Nucleotide_resolution.pdf")
|
||||
|
||||
#Loop through all genes.
|
||||
for (i in 1:length(dat)) {
|
||||
|
||||
#Get data for this gene.
|
||||
this_dat <- dat[[i]]
|
||||
|
||||
#Reformat data for plotting.
|
||||
this_dat <- melt(this_dat, id.vars = "Position")
|
||||
|
||||
#Store the plot in a variable.
|
||||
p <- ggplot(this_dat, aes(x = Position, y = value)) +
|
||||
geom_bar(stat = "identity") +
|
||||
facet_grid(variable ~ .)+
|
||||
scale_y_continuous(breaks = c(0, 0.5, 1))+
|
||||
ylab("Signal")+
|
||||
annotate(geom = "rect",
|
||||
xmin = to_annotate$Start[i],
|
||||
xmax = to_annotate$End[i],
|
||||
ymin = -Inf,
|
||||
ymax = Inf, fill = "red",
|
||||
color = NA,
|
||||
alpha = 0.3) +
|
||||
ggtitle(names(dat)[i])
|
||||
|
||||
#Print plot to file.
|
||||
print(p)
|
||||
}
|
||||
|
||||
#Close file.
|
||||
dev.off()
|
||||
Loading…
Add table
Add a link
Reference in a new issue