Acerca de… si es que el R sirve para todo.

October 28, 2011
By

This post was kindly contributed by Acerca de... » R - go there to comment and to read the full post.

En el blog sobre ecología y evolución EBB Flow. Nos han felicitado Halloween con una tarjeta hecha en R.

Os pego el código:


###required libraries
##if you do not have the "fields" and "MBA" libraries, you need this step to install them
install.packages("fields")
install.packages("MBA")
## load libraries
library(fields)
library(MBA)

###data
data<-matrix(c(44.9186,81.0824,46.9512,80.1061,49.187,80.7055,57.9268,80.1493,60.3659
 ,81.34,69.3089,80.1941,78.4553,79.2459,91.8699,70.834,99.7967,55.9047
 ,101.2195,30.9102,96.1381,17.3075,85.5691,7.4235,74.3902,4.2299
 ,61.7886,1.8181,55.4878,1.0059,49.187,0.9811,45.3252,1.7532,37.1951
 ,1.9181,20.3252,7.1666,8.9431,17.1612,4.2683,29.1507,4.2683,50.8042
 ,9.5528,66.3761,18.4959,76.2539,29.065,80.6261 ,38.6179,80.8607
 ,44.9186,81.0824)
 ,ncol=2,byrow=TRUE)
stem<-matrix(c(60.3659,81.34,57.9268,80.1493,49.187,80.7055,46.9512,80.1061,44.9186
 ,81.0824,45.5285,83.6438,47.561,88.1794,44.1057,97.2209,48.7805,99.9952
 ,54.878,87.6176,60.3659,81.34)
 ,ncol=2,byrow=TRUE)
eye<-matrix(c(45.935,46.4407,34.1463,44.8195,36.7886,46.9952,36.382,50.9306,32.3171,53.08
 ,29.065,53.0672,26.0163,49.7086,28.0488,45.1892,20.3252,48.7021,20.1219
 ,55.3942,23.5772,61.1164,30.8942,65.476,32.3171,59.7729,45.935,46.4407)
 ,ncol=2,byrow=TRUE)
eye2<-matrix(c(58.9431,46.6888,65.4472,51.2419,71.748,56.9754,74.3902,65.4504,82.7236
 ,59.7745,84.9593,56.4368,84.7561,48.562,77.439,45.7772,78.8618,50.5072
 ,74.3902,53.6393,69.9186,51.6532,68.6992,47.9083,70.5285,44.9627,58.9431
 ,46.6888)
 ,ncol=2,byrow=TRUE)
mouth<-matrix(c(8.9431,44.7202,23.374,41.2338,30.0813,22.7562,38.2114,38.5363,65.0407
 ,38.445,73.374,22.533,80.2846,40.8673,96.9512,44.673,93.4959,31.8641
 ,84.1463,18.8352,66.2602,9.7097,61.9919,16.1889,59.3496,8.3045,45.5285
 ,8.447,42.8862,16.1137,38.2114,9.4024,22.7642 ,17.4125,11.9919,31.7401
 ,8.9431,44.7202)
 ,ncol=2,byrow=TRUE)
stars<-matrix(c(sample(seq(0,100),80),sample(seq(20,100),80,replace=TRUE)),ncol=2)

###plot
par(bg = "black")
par(mar=c(5,2,4,2))+0.1
plot(data,type="n",xlim=c(0,100),ylim=c(0,100),xaxt="n",yaxt="n",xlab="",ylab="",axes=FALSE)
symbols(x=stars[,1],y=stars[,2]
 ,circles=rep(0.001,nrow(stars))
 ,inches=0.015,bg="white"
 ,xlim=c(0,100),ylim=c(0,100))
col<-runif(nrow(data),min=4,max=7)
datmb<-mba.surf(matrix(cbind(data,col),ncol=3),no.X=200,no.Y=200,extend=FALSE)
image(datmb$xyz,zlim=c(0,10),col=heat.colors(40),add=TRUE)
polygon(stem,col="darkgreen")
polygon(eye,col="yellow")
polygon(eye2,col="yellow")
polygon(mouth,col="yellow")
points(data,type="l")
mtext("Happy Halloween",side=3,col="green3",cex=3.5,font=4)
mtext("from the EEB and Flow",side=1,col="green3",cex=2.5,font=4)

Ale, a destriparlo y a aprender cosas sobre gráficos en R.

No os perdáis el segundo comentario.

jaume


Filed under: General, open source, R Tagged: Halloween, R, R cran

Tags: , , , ,

Comments are closed.