Introduction to R


TP 3: Graphics and data.frames

Prof. Patrick Meyer

BioSys Lab - Université de Liège

Simple graphics

  1. pairs(CO2[,-1])

    explication:

  2. explication:

data.frame

  1. write.table(CO2,file="mydata.txt",sep=",")
    mydata <- read.table("mydata.txt",sep=",",header=T)
    

    explication:

    Complement:

  2. sum(CO2$Type=="Quebec" & CO2$uptake>35 & CO2$Treatment=="chilled")

    explication:

  3. index <- which(CO2$conc==min(CO2$conc))
    which(CO2$uptake==max(CO2$uptake[index]))
    

    explication:


  4. maxuptake <- function(nameplant){
      max(CO2$uptake[CO2$Plant==nameplant])
    }
    maxvec <- sapply(levels(CO2$Plant),maxuptake)
    

    explication:

Advanced graphics

  1. minuptake <- function(nameplant){
      min(CO2$uptake[CO2$Plant==nameplant])
    }
    minmaxmat <- rbind(sapply(levels(CO2$Plant),minuptake),maxvec)
    barplot(minmaxmat,beside=T,col=c("red","blue"),main="minima and maxima of uptakes by plant")
    

    explication:

  2. uptakemat <- matrix(CO2$uptake,nr=7)
    rownames(uptakemat) <- CO2$conc[1:7]
    colnames(uptakemat) <- unique(CO2$Plant)
    heatmap(uptakemat,Rowv=NA,Colv=NA)
    

    explication:

  3. par(mfrow=c(1,2))
    plot(CO2$conc,CO2$uptake)
    barplot(minmaxmat,col=c("red","blue"),main="minima and maxima of uptakes by plant")
    

    explication:


<--- BACK