HardOCP has an image with an equation which apparently draws the Batman logo.

\( ((\frac{x}{7})^2 \cdot \sqrt{\frac{||x|-3|}{(|x|-3)}}+ (\frac{y}{3})^2 \cdot \sqrt{\frac{|y+3 \cdot \frac{\sqrt{33}}{7}|}{y+3 \cdot \frac{\sqrt{33}}{7}}}-1) \cdot (|\frac{x}{2}|-((3 \cdot \frac{\sqrt{33}-7)}{112}) \cdot x^2-3+\sqrt{1-(||x|-2|-1)^2}-y) \cdot (9 \cdot \sqrt{\frac{|(|x|-1) \cdot (|x|-0.75)|}{((1-|x|)*(|x|-0.75))}}-8 \cdot |x|-y) \cdot (3 \cdot |x|+0.75 \cdot \sqrt{\frac{|(|x|-0.75) \cdot (|x|-0.5)|}{((0.75-|x|) \cdot (|x|-0.5))}}-y) \cdot (2.25 \cdot \sqrt{\frac{|(x-0.5) \cdot (x+0.5)|}{((0.5-x) \cdot (0.5+x))}}-y) \cdot (\frac{6 \cdot \sqrt{10}}{7}+(1.5-0.5 \cdot |x|) \cdot \sqrt{\frac{||x|-1|}{|x|-1}}-(\frac{6 \cdot \sqrt{10}}{14}) \cdot \sqrt{4-(|x|-1)^2}-y) =0 \)
This function is very delightful for drawing such a graph, but write it down in latex is very tedious.
As a product of factors is 0 if and only if any one of them is 0, multiplying these six factors puts the curves together. This graph is no more than the combination of six curves.
All these six curves are very simple, for instance, the first factor is the ellipse \( (\frac{x}{7})^2 + (\frac{y}{3})^2 = 1 \), in the region where |x|>3 and y>-3\( \sqrt{33} \)/7; the region were restricted by \( \sqrt{\frac{||x|-3|}{(|x|-3)}} \) and \( \sqrt{\frac{|y+3 \cdot \frac{\sqrt{33}}{7}|}{y+3 \cdot \frac{\sqrt{33}}{7}}} \)
Here's what I got from the equation using ggplot2...

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | require(ggplot2) f1 <- function(x) { y1 <- 3*sqrt(1-(x/7)^2) y2 <- -3*sqrt(1-(x/7)^2) y <- c(y1,y2) d <- data.frame">data.frame(x=x,y=y) d <- d[d$y > -3*sqrt(33)/7,] return(d) } x1 <- c(seq(3, 7, 0.001), seq(-7, -3, 0.001)) d1 <- f1(x1) p1 <- ggplot(d1,aes(x,y)) + geom_point(color="red") x2 <- seq(-4,4, 0.001) y2 <- abs(x2/2)-(3*sqrt(33)-7)*x2^2/112-3 + sqrt(1-(abs(abs(x2)-2)-1)^2) #only work with ggplot2 <= 0.8.9 #p2 <- p1 + geom_point(aes(x=x2,y=y2), color="yellow") # in ggplot2 0.9.0, should be: d2 <- data.frame">data.frame(x2=x2, y2=y2) p2 <- p1 + geom_point(data=d2, aes(x=x2,y=y2), color="yellow") x3 <- c(seq(0.75,1,0.001), seq(-1,-0.75,0.001)) y3 <- 9-8*abs(x3) #p3 <- p2+geom_point(aes(x=x3,y=y3), color="green") d3 <- data.frame">data.frame(x3=x3, y3=y3) p3 <- p2+geom_point(data=d3, aes(x=x3,y=y3), color="green") x4 <- c(seq(0.5,0.75,0.001), seq(-0.75,-0.5,0.001)) y4 <- 3*abs(x4)+0.75 #p4 <- p3+geom_point(aes(x=x4,y=y4), color="steelblue") d4 <- data.frame">data.frame(x4=x4,y4=y4) p4 <- p3+geom_point(data=d4, aes(x=x4,y=y4), color="steelblue") x5 <- seq(-0.5,0.5,0.001) y5 <- rep(2.25,length(x5)) #p5 <- p4+geom_point(aes(x=x5,y=y5)) d5 <- data.frame">data.frame(x5=x5,y5=y5) p5 <- p4+geom_point(data=d5, aes(x=x5,y=y5)) x6 <- c(seq(-3,-1,0.001), seq(1,3,0.001)) y6 <- 6 * sqrt(10)/7 + (1.5 - 0.5 * abs(x6)) * sqrt(abs(abs(x6)-1)/(abs(x6)-1)) - 6 * sqrt(10) * sqrt(4-(abs(x6)-1)^2)/14 #p6 <- p5+geom_point(aes(x=x6,y=y6), colour="blue") d6 <- data.frame">data.frame(x6=x6,y6=y6) p6 <- p5+geom_point(data=d6,aes(x=x6,y=y6), colour="blue") p <- p6+theme_bw() print(p) |
- Pingback on 2011/08/15/ 07:08
- Pingback on 2012/02/15/ 15:13

When I (mindlessly) run the above R script, I get the Console error output:
> print(p)
Error in data.frame(..., check.names = FALSE) :
arguments imply differing number of rows: 8001, 14002
and a blank plot canvass.
I was able to narrow this error down to p2:
> p2
Error in data.frame(..., check.names = FALSE) :
arguments imply differing number of rows: 8001, 14002
p1 plots the 2 base ellipse components (outer wings) correctly.
Reply
ygc
Reply:
August 15th, 2011 at 12:47 am
you did not run the following command correctly.
Your error is due to the typo. You key in x or y instead of x2 or y2, and geom_point will parse it according to the dataset provided by p1.
Reply
I am trying to run the batman curve with R2.14.2 and ggplot2 0.9.0
I am now getting the same error message as Rudy Rooz reported.
I did not get that error message before.
What has changed with ggplot? Any idea how to repair this?
Reply
ygc
Reply:
March 20th, 2012 at 11:33 am
corrected, now work with ggplot2 0.9.0.
Reply