Skip to content

Instantly share code, notes, and snippets.

@dengemann
Forked from smacarthur/gist:733313
Created July 13, 2013 19:05

Revisions

  1. @smacarthur smacarthur revised this gist Dec 10, 2010. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion gistfile1.r
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,8 @@
    ### Load the package or install if not present
    if (!require("RColorBrewer")) install.packages("RColorBrewer")
    if (!require("RColorBrewer")) {
    install.packages("RColorBrewer")
    library(RColorBrewer)
    }

    ### Set the display a 2 by 2 grid
    par(mfrow=c(2,2))
  2. @invalid-email-address Anonymous created this gist Dec 8, 2010.
    26 changes: 26 additions & 0 deletions gistfile1.r
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    ### Load the package or install if not present
    if (!require("RColorBrewer")) install.packages("RColorBrewer")

    ### Set the display a 2 by 2 grid
    par(mfrow=c(2,2))

    ### Show all the colour schemes available
    display.brewer.all()

    ### Generate random data matrix
    rand.data <- replicate(8,rnorm(100,100,sd=1.5))

    ### Draw a box plot, with each box coloured by the 'Set3' palette
    boxplot(rand.data,col=brewer.pal(8,"Set3"))

    ### Draw plot of counts coloured by the 'Set3' pallatte
    br.range <- seq(min(rand.data),max(rand.data),length.out=10)
    results <- sapply(1:ncol(rand.data),function(x) hist(rand.data[,x],plot=F,br=br.range)$counts)
    plot(x=br.range,ylim=range(results),type="n",ylab="Counts")
    cols <- brewer.pal(8,"Set3")
    lapply(1:ncol(results),function(x) lines(results[,x],col=cols[x],lwd=3))

    ### Draw a pie chart
    table.data <- table(round(rand.data))
    cols <- colorRampPalette(brewer.pal(8,"Dark2"))(length(table.data))
    pie(table.data,col=cols)