Setting a scale in ggplot2
scale_y_continuous(limits = c(10, 200))
Month: December 2010
Moving average in R Median: runmed() M …
Moving average in R
Median: runmed()
Mean: filter()
ex)
runmed(data, 3)
filter(data, rep(1/3, 3))
Save ggplot in pdf Use dev.copy2pdf(fil …
Save ggplot in pdf
Use dev.copy2pdf(file=”plot.pdf”)
Example)
plotA <- ggplot() + geom_line(data=nucleosome.mono.colsum, aes(seq, y=A, colour="A") )
plotT <- ggplot() + geom_line(data=nucleosome.mono.colsum, aes(seq, y=T, colour="T") )
arranged.plot <- grid.arrange(plotA, plotT, nrow=2)
dev.copy2pdf(file="arranged.plot")
dev.off()
# Running R in batch mode R CMD BATCH R …
# Running R in batch mode
R CMD BATCH Rscript.R
Object in R Factor can be used for sequ …
Object in R
Factor can be used for sequence data.
From sequence characters
seq <- c("A", "C", "C", "T", "G")
seq.factor <- factor(seq, levels=c("A", "G", "T", "C")
From numbers to sequences
> seq.num <- c(1,2,3,1,1,3,2,1,4,1,3,2,1)
> seq.num.factor <- factor(seq.num, levels=c(1,2,3,4), labels=c("A","G","T","C") )
There seems to be a bug in a R package n …
There seems to be a bug in a R package named pgam:periodogram().
The function intensity happened to have two cos. One of them should be sin.
Here is the correct version.
function (w, x)
{
n <- length(x)
t <- seq(1:n)
sp <- ((sum(x * cos(w * t)))^2 + (sum(x * sin(w * t)))^2)/n
return(sp)
}
R vector does not have dimension. It onl …
R vector does not have dimension. It only has length.
On the other hand, matrix has dimension.
R commands to explore time series data …
R commands to explore time series data
ts(data) # create time series objects
time(ts.data) # returns the time
diff(ts.data, lag=1) # difference at the specified lag
lag.plot(ts.data, 9, do.lines=FALSE) # plot with specified lags
plot(stl(ts.data, “per”)) # decomposition of time series data
spec.pgram(ts.data, spans=c(3,3), log=”no”) # non-parametric spectral analysis
spec.ar(ts.data, spans=c(3,3), log=”no”) # parametric estimation
http://www.stat.pitt.edu/stoffer/tsa2/R_time_series_quick_fix.htm
R commands examining data and its struct …
R commands examining data and its structures
ls() or objects() # list variables
structure()
str() # summary of data
levels()
dim() # dimension of data
class() # show the class of the variable
head() or tail() # showing parts of data
http://www.statmethods.net/input/contents.html
R normality tests shapiro.test() his …
R normality tests
shapiro.test()
hist(data, prob=TRUE)
lines(density(data))
qqnorm(data)
qqline(data)