Friday, July 8, 2011

Plotting Small Samples with R.

R has a comprehensive set of routines for visualization of data. Here we show some of its capabilities on  a small sample Y containing positive values.


library("vioplot")

X <- c(rnorm(50, 10, 3),rnorm(50, 15, 5))
Y <- c(runif(10, 5, 20))


par(mfrow=c(3,3))

pie(Y, main="Small sample", sub="A Pie Chart")
dotchart(Y, main="Small sample", sub="A Dot Chart")
stripchart(Y, main="Small Sample", sub="A Strip chat")

barplot(Y, main="Small sample", sub="A vertical Bar Chart")
barplot(Y, horiz=T, main="Small sample", sub="A Horizontal Bar Chart")

boxplot(Y, main="Small sample", sub="A box plot")
vioplot(Y)  # package vioplot
title <- "A vio plot"

plot(Y, type="p", main="Small Sample", sub="A Scatterplot")
plot(Y, type="l", main="Small Sample", sub="A Line plot")



First a few observations:

  1.The vioplot function does not allow seting the main title or sub title. Instead you should call title("title of graph") after the call to vioplot.

  2. Pie charts are not well loved by statisticians, they cannot represent negative values and its difficult to judge magnitudes.



Here is a screenshot of the small sample plots.


Next time we will present plots which can handle a larger number of data points.

No comments:

Post a Comment