inst/doc/practical1.R

## ----setup, include=FALSE, cache=FALSE-----------------------------------
library(knitr)
options(replace.assign=FALSE,width=50)

opts_chunk$set(fig.path='figure/graphics-', 
               cache.path='cache/graphics-', 
               fig.align='center', 
               dev='pdf', fig.width=5, fig.height=5, 
               fig.show='hold', cache=FALSE, par=TRUE)
knit_hooks$set(crop=hook_pdfcrop)

knit_hooks$set(par=function(before, options, envir){
    if (before && options$fig.show!='none') {
        par(mar=c(3,3,2,1),cex.lab=.95,cex.axis=.9,
            mgp=c(2,.7,0),tcl=-.01, las=1)
}}, crop=hook_pdfcrop)


## ----include=FALSE-------------------------------------------------------
opts_chunk$set(concordance=TRUE)


## ------------------------------------------------------------------------
x = 5


## ----eval=FALSE, tidy=FALSE----------------------------------------------
## install.packages("nclRcourses",
##                  repos="http://R-Forge.R-project.org")


## ------------------------------------------------------------------------
library(nclRcourses)


## ------------------------------------------------------------------------
data(yeast_long)


## ------------------------------------------------------------------------
## yeast_long is a data frame
colnames(yeast_long)


## ------------------------------------------------------------------------
colnames(yeast_long)[1]
colnames(yeast_long)[1] = "id"


## ----results='hide'------------------------------------------------------
yeast_long$value


## ----results='hide'------------------------------------------------------
yeast_long[,2]


## ------------------------------------------------------------------------
head(yeast_long$value, 5)


## ----fig.keep='none'-----------------------------------------------------
## Select all measurements on the first probe
d = yeast_long[1:15,]
plot(d$tps, d$value) 


## ----test-plot, fig.keep='none'------------------------------------------
plot(d$tps, d$value, xlab="A nice label")


## ----pdf-dev, ref.label='test-plot', dev='pdf', out.width='\\textwidth', echo=FALSE, crop=TRUE----


## ----fig.keep='none'-----------------------------------------------------
plot(d$tps, d$value, col=d$rep)


## ----eval=FALSE, tidy=FALSE----------------------------------------------
## par(mar=c(3,3,2,1), mgp=c(2,.7,0), tck=-.01,
##     las=1)


## ----F2, fig.keep="none"-------------------------------------------------
hist(yeast_long$value)


## ----ref.label='F2', dev='pdf', out.width='\\textwidth', echo=FALSE------


## ----fig.keep="none"-----------------------------------------------------
hist(yeast_long$value, breaks="FD")


## ----F3, fig.keep="none"-------------------------------------------------
boxplot(yeast_long$value)


## ----ref.label='F3', out.width='\\textwidth', echo=FALSE-----------------


## ----fig.keep="none"-----------------------------------------------------
boxplot(yeast_long$value ~ yeast_long$type)


## ----tidy=FALSE----------------------------------------------------------
cols = c(rgb(85, 130, 169, alpha=40, maxColorValue=255), 
         rgb(200, 79, 178, alpha=200, maxColorValue=255))


## ----tidy=FALSE----------------------------------------------------------
par(mar=c(3,3,2,1), mgp=c(2,0.4,0), tck=-.01,
    cex.axis=0.9, las=1, xaxs='i', yaxs='i')


## ----f4,tidy=FALSE, fig.keep='none', echo=1:3----------------------------
plot(d[1:5,]$tps, d[1:5, ]$value, type="l", frame=FALSE, 
     axes=FALSE,
     panel.first=abline(h=seq(8.75, 9.5, 0.25),  
                        lwd=3, col="lightgray", lty="dotted"), 
     xlab="Time", ylab="Expression level", 
     xlim=c(0, 250), ylim=c(8.5, 9.5), 
     col=cols[1], lwd=2, cex.lab=0.9)
lines(d[6:10,]$tps, d[6:10, ]$value, col=cols[1], lwd=2)
lines(d[11:15,]$tps, d[11:15, ]$value, col=cols[1], lwd=2)

axis(2, c(8.5, 9, 9.5), c("8.5", "9.0", "9.5"), tick=F, cex.axis=0.8)
axis(1, seq(0, 250, 50), seq(0, 250, 50), cex.axis=0.8)
title("Expression levels of 1769308_at", adj=0, 
      cex.main=0.9, font.main=2, col.main="black")
lines(seq(0, 240, 60), tapply(d$value, d$tps, mean), 
      col=cols[2], lwd=2)


## ----ref.label='f4', fig.keep='last', echo=FALSE-------------------------


## ----f4b,eval=FALSE, tidy=FALSE------------------------------------------
## axis(2, c(8.5, 9, 9.5), c("8.5", "9.0", "9.5"), tick=FALSE,
##      cex.axis=0.8)
## axis(1, seq(0, 250, 50), seq(0, 250, 50), cex.axis=0.8)
## title("Expression levels of 1769308_at", adj=0,
##       cex.main=0.9, font.main=2, col.main="black")


## ----eval=FALSE, tidy=FALSE----------------------------------------------
## lines(seq(0, 240, 60), tapply(d$value, d$tps, mean),
##       col=cols[2], lwd=2)

Try the nclRcourses package in your browser

Any scripts or data that you put into this service are public.

nclRcourses documentation built on May 2, 2019, 5:55 p.m.