# [R Graphics] Beautiful graphics thread

#### bryangoodrich

##### Probably A Mammal
I like the graph trinker! I wonder what other aggregation we can do, maybe something that accounts for timezone (since every hour is locally different), and include a scale on the right to show what the continuous variable represents (graphs need to be completely informative, at least in the final analysis).

#### TheEcologist

##### Global Moderator
I decided to showcase the use of images in R graphics.

Lets take a look at the forum's from a spammer perspective. Generally speaking its a dangerous place, with ravenous moderators around each corner waiting to devour their posts and ban them for all eternity. Thus lets see how the TS mods compare in evil (from a spammers perspective) to famous cinema villains.

Using data from the net, on villain body counts and comparing these to the mod ban statistics we can get a mle estimate of how the mods compare to famous villains. This finally give us an opportunity to scientifically prove who is a raptor and who is a (Skynet) bot. [I would want to compare mods to super heroes but there is no way to rank super heroes objectively that I can think of]. In the analysis I assume that ban stats are a Poisson distributed random variable.

So here are the results;

And here is the script (make sure to download the images zip file and set your working directory);

Code:
#have you set your image working directory yet?

setwd("/home/marco/images")

killcount=sort(structure(c(9L, 6L, 89L, 33L, 8L, 34L), .Dim = 6L, .Dimnames = structure(list(
dat = c("bugman", "CowboyBear", "Dason", "Dragan", "quark",
"TheEcologist")), .Names = "dat"), class = "table"))

# Movie Villains kill stats taken from the net
villains=structure(list(Kills = c(6, 10, 18, 22, 32, 35, 42, 57, 64),
name = structure(c(8L, 1L, 5L, 2L, 3L, 4L, 6L, 9L, 7L), .Label = c("Alien",
"Predator", "Raptors", "Terminator"), class = "factor")), .Names = c("Kills",
"name"), row.names = c(4L, 3L, 5L, 7L, 8L, 6L, 9L, 2L, 1L), class = "data.frame")

#blood palette
tibetanmonk.colors=colorRampPalette(c("#FC580C","#FC6B0A","#F8872E","#FFA927","#FDCA49"))

# Blood splash background
require(biOps)

text(1,1,"A")

layoutmat=
structure(c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 77L, 1L, 17L, 26L, 35L,
44L, 53L, 62L, 8L, 1L, 18L, 27L, 36L, 45L, 54L, 63L, 9L, 1L,
19L, 28L, 37L, 46L, 55L, 64L, 10L, 1L, 20L, 29L, 38L, 47L, 56L,
65L, 11L, 1L, 21L, 30L, 39L, 48L, 57L, 66L, 12L, 1L, 22L, 31L,
40L, 49L, 58L, 67L, 13L, 1L, 23L, 32L, 41L, 50L, 59L, 68L, 14L,
1L, 24L, 33L, 42L, 51L, 60L, 69L, 15L, 1L, 25L, 34L, 43L, 52L,
61L, 70L, 16L, 1L, 71L, 72L, 73L, 74L, 75L, 76L, 1L), .Dim = c(8L,
11L), .Dimnames = list(NULL, c("V1", "V2", "V3", "V4", "V5",
"V6", "V7", "V8", "V9", "V10", "V11")))

Avatars=vector("list",5)

par(mar=c(0,0,0,0),xaxt="n",yaxt="n")
layout(layoutmat)

plot(bloodbackground)

lims=dim(bloodbackground)[1:2]

#Title
text(lims[2]/2,lims[1]-40,expression(bold("How Moderators Compare to Movie Villains")),cex=3,col="blue")

# MLE
text(lims[2]-40,lims[1]-60,expression(bold("MLE")),cex=2,col="blue")

#mod
text(0+40,lims[1]-60.5,expression(bold("MOD")),cex=2,col="blue")

for(i in 1:6){
plot(Avatars[[i]])
}

for(i in 1:9){
plot(vilpic)
}

for(i in 1:6){

for (j in 1:dim(villains)[1]){
barplot(dpois(villains[j,1],killcount[i]),
col=tibetanmonk.colors(dim(villains)[1])[j],
ylim=c(0,max(dpois(villains[,1],killcount[i]))))
}
}

for(i in 1:6){
l=dpois(villains[,1],killcount[i])
mle=which(l==max(l))
[mle],".jpg",sep=""))
plot(vilpic)
}

plot(-100,ylim=c(0,1),xlim=c(0,1))
As we can see there are certainly Raptors on the forum, Dragan is as deadly as Chucky, Dason is likely the Predator but cant be significantly distinguished from the T101 (a bot). Quark, like his DS9 Ferengi bar-tender counterpart, is likely an Alien (but still most likely a Raptor)... bugman will incubate his spawn in your abdomen... and funny enough I'm Darth Vader.

So come on over to the Darkside and join me in the power of (wrapper free) R graphics

Note; the mod stats may not reflect actual clean-up contributions of the moderators, as we have an automatic spammer "remove all posts and ban" button.. which does not get recorded in the stats. Some mods may therefore be more deadly than the image suggests

#### TheEcologist

##### Global Moderator
Does this mean quark is a raptor?
Indeed a Raptor. But it really all boils down towards whether you are a Frequentest or a Bayesian. You see the mode of the likelihood distribution is a Raptor, but Bayesians would be more interested in the mean which is an Alien , I w

Also, as I am Darth Vader, I would like to urge bugman to finish that death star in his avatar. I want it fully operational!

#### vinux

##### Dark Knight
Happy birthday to Velociraptor. I made this one using raptor's favourite package

Code:
rapt = read.csv("http://dl.dropbox.com/u/32095775/raptor.csv")
library(ggplot2)
ggplot(data=rapt) + geom_polygon(aes(x=V1, y=V2, group=group), colour=I("gray") )+ theme_bw() + scale_x_continuous(limits = c(0, 400)) +   scale_y_continuous(limits = c(0, 250)) +
geom_text(aes(100,230, label="Happy Birthday Raptor"))+
theme(axis.line=element_blank(), axis.text.x=element_blank(),  axis.text.y=element_blank(),axis.ticks=element_blank(), axis.title.x=element_blank(),    axis.title.y=element_blank(),legend.position="none", panel.background=element_blank(),panel.border=element_blank(), panel.grid.major=element_blank(), panel.grid.minor=element_blank(), plot.background=element_blank())

#### Dason

*snip*

Some mods may therefore be more deadly than the image suggests
So we've been having some mass spamming lately and it's definitely easier to take care of big chunks of spammers using methods that do get counted by the forum. I'm up to 490 now. I only bring it up because this puts me much further away from the raptor on that chart.

#### Nathan G

##### New Member
Thought I'd chime in if nobody minds with the Breather surface..
Code:
require(misc3d)

a <- 2/5

wsqr <-  1 - a^2
w <- sqrt(wsqr)
denom <- function(a,w,u,v) a*((w*cosh(a*u))^2 + (a*sin(w*v))^2)

fx <- function(u,v) -u + (2*wsqr*cosh(a*u)*sinh(a*u)/denom(a,w,u,v))
fy <- function(u,v) 2*w*cosh(a*u)*(-(w*cos(v)*cos(w*v)) - (sin(v)*sin(w*v)))/denom(a,w,u,v)
fz = function(u,v) 2*w*cosh(a*u)*(-(w*sin(v)*cos(w*v)) + (cos(v)*sin(w*v)))/denom(a,w,u,v)

parametric3d(fx = fx, fy = fy, fz = fz,
umin = -17,
umax = 17,
vmin = -77,
vmax = 77,
n = 100,
color = c("grey17","grey21","red4","darkred","red4","grey21","grey17"),
engine = "rgl")

#### TheEcologist

##### Global Moderator
I wonder if anyone would be up for the challenge of creating an R script that will draw a raptor with as little parameters as possible?

Would make a fantastic example of the principle of parsimony

#### vinux

##### Dark Knight
I wonder if anyone would be up for the challenge of creating an R script that will draw a raptor with as little parameters as possible?

Would make a fantastic example of the principle of parsimony
I am ready for this challenge.

What about recreating the old one historical milestones with the oldy (Something like it has scanned from old book) look.

#### TheEcologist

##### Global Moderator
One of the most painful experiences is selecting colors in R.

As I was fooling around with github, I thought I might just upload my color selection tools.

One of the cool things that they let you do is choose colors interactively.

I use the follow functions quite a bit;

color.choose()
color.wheel()
pallete.picker()

So please, let me know if you like them, have any suggestions, or think I should develop them further (aka if they will be valued by a larger audience).

Cheers,

TE

#### Dason

You should turn that into a package.

#### TheEcologist

##### Global Moderator
You should turn that into a package.
I am going to do that now, in the style of your awesome and criminally underrated "findPackage".

Or do you mean go all the way to CRAN?

#### trinker

##### ggplot2orBust
I love the idea. I ran into a few bumps but didn't debug it:

Code:
> mycol<-color.choose()
> mycol
[1] "#00B8D8"
> Mypallet<-pallette.picker(n=5)
Error: could not find function "pallette.picker"
> color.wheel()
Error in seq.default(0, 1, length.out = N) : object 'N' not found

#### TheEcologist

##### Global Moderator
I love the idea. I ran into a few bumps but didn't debug it:
Ouch, some spelling issues. But in my defense, palette is french

These issues should now be solved.

#### TheEcologist

##### Global Moderator
You should turn that into a package.
It is now officially a package (in development).

I would appreciate if anyone wanted to test it!

#### vinux

##### Dark Knight
What about recreating the old one historical milestones with the oldy (Something like it has scanned from old book) look.
I was thinking of this one for longtime. Here is one recreation of plot of Minard (Charles Minard visualised the losses of the French Army in the Russian campaign of Napoleon)

http://www.datavis.ca/gallery/re-minard.php

(A ggplot version also included -with the code).

Here is the actual Charles Minard's flow map of Napoleon's March

#### vinux

##### Dark Knight
@vinux were you proposing we tackle this? On that page you linked to it seems some have already tackled it in R. I have seen Hadley demo a ggplot2 version of this. Here's one:

http://fportman.com/data-visualization-with-r/visualizing-napoleon-s-march-to-moscow/
May be we can try another one (eg: Florence Nightingale's Coxcomb diagram or Playfair's charts )

Those seems to be easy to recreate.. But I was trying to create the graphs as if it made long ago (without photoshop/gimp or any other pic s/w)