Monday, October 4, 2010

R blogs and gallery

http://addictedtor.free.fr/graphiques/

http://www.statmethods.net/input/missingdata.html
# create new dataset without missing data
newdata <- na.omit(mydata)  

 

Reshaping data

# example of melt function
library(reshape)
mdata <- melt(mydata, id=c("id","time")) 
# Creating a Graph with a linear model regression line
attach(mtcars)
plot(wt, mpg)
abline(lm(mpg~wt))
title("Regression of MPG on Weight")

# Filled Density Plot
d <- density(mtcars$mpg)
plot(d, main="Kernel Density of Miles Per Gallon")
polygon(d, col="red", border="blue") 

Comparing Groups VIA Kernal Density

The sm.density.compare( ) function in the sm package allows you to superimpose the kernal density plots of two or more groups. The format is sm.density.compare(x, factor) where x is a numeric vector and factor is the grouping variable.
# Compare MPG distributions for cars with
# 4,6, or 8 cylinders
library(sm)
attach(mtcars)

# create value labels
cyl.f <- factor(cyl, levels= c(4,6,8),
  labels = c("4 cylinder", "6 cylinder", "8 cylinder"))

# plot densities
sm.density.compare(mpg, cyl, xlab="Miles Per Gallon")
title(main="MPG Distribution by Car Cylinders")

# add legend via mouse click
colfill<-c(2:(2+length(levels(cyl.f))))
legend(locator(1), levels(cyl.f), fill=colfill)



http://yihui.name/en/page/2/
http://yihui.name/en/2009/06/creating-tag-cloud-using-r-and-flash-javascript-swfobject/#more-224 - Tag Cloud

Side by side plot

# png(width = 500, height = 300)
x = rep(0, 1000)
par(mfrow = c(1, 2), mar = c(4, 4, 0.1, 0.1))
plot(density(x), main = "")
plot(density(x), main = "")
rug(jitter(x))
# dev.off()

# transparent colors (alpha = 0.1)
plot(x, col = rgb(0, 0, 0, 0.1))


http://processtrends.com/RClimate.htm 
## Use regexp to replace all the occurences of **** with NA
lines2 <- gsub("\\*{3,5}", " NA", lines, perl=TRUE)
## Select monthly data in first 13 columns
df <- df[,1:13]
## Remove rows where Year=NA from the dataframe
df <- df [!is.na(df$Year),] 

No comments: