Finally a useful R function

Science, Stuff

Here my first R function that generates random mountain views with a swarm of birds in the front…

##Mountain view code
library("ggplot2")
library("reshape")

#the function
mountain = function(){
a = rnorm(222, mean = runif(1, 0, 30), sd = runif(1, 5, 20))
b = rnorm(222, mean = runif(1, 20, 60), sd = runif(1, 5, 20))
c = rnorm(222, mean = runif(1, 0, 30), sd = runif(1, 5, 20))
d = rnorm(222, mean = runif(1, 30, 60), sd = runif(1, 5, 20))
e = rnorm(222, mean = runif(1, 0, 60), sd = runif(1, 5, 20))
f = rnorm(222, mean = runif(1, 0, 60), sd = runif(1, 5, 20))

dataS= cbind(a,b,c,d,e,f)
dataS2 = melt(dataS)

rr = runif(2,5,300)
g = runif(1, min(dataS2$value), max(dataS2$value))
h = runif(30, min(rr), max(rr))*0.0001
i = runif(30, g-runif(1,5,30), g + runif(1,5,30))
birds = data.frame(cbind(g,h,i))
#quartz(width = 7, height = 3.5) #uncomment this if on mac
p = ggplot(data = dataS2, group = X2) 
p + geom_density(aes(value,color = factor(X2), fill = factor(X2))) + 
scale_fill_brewer(type="seq", palette = "Greys") + 
scale_color_brewer(type="seq", palette = "Greys") + 
scale_x_continuous("Mountain view") + scale_y_continuous("") + 
geom_point(data = birds,aes(x=i,y=h, pch = 4)) + 
opts(legend.position = "none")  + 
opts(axis.text.x = theme_blank(), axis.text.y = theme_blank(), axis.ticks = theme_blank())  + 
coord_equal(ratio = 0.5) + opts(aspect.ratio = 0.5)
}

#the call
mountain()