# Maths, Music and Merkbar

Control is what we already know. Control is where we have already ventured. Control is what helps us predict the future. (Merkbar)

Maths and music get along very well. Last December I received a mail from a guy called Jesper. He is one of the two members of Merkbar: a electronic music band from Denmark. As can be read in their website:

Merkbar is Jesper and David who are both interested in the psychedelic worlds and oriental spiritualism. They both studied Computer Music, where they’ve done research in sound synthesis, generative composition and the design of new digital instrument.

They asked me a front cover for their new album which will be released at the beginning of 2015. Why? Because they liked this post I did about circlizing numbers.  To do this plot I circlized the Golden Ratio number (Phi). But in this case I changed ribbons (all equal pairs of consecutive numbers gather together) by lines (every pair of consecutive numbers form a different line). As I did before, I used `circlize` package, which implements in R the features of Circos, a software to create stunning circular visualizations.

The final plot represents the first 2.000 digits of Phi: You can hear an advancement of their new album here, which is called “Phi”. Enjoy their sensitive and full-of-shades music: you will be delightfully surprised as I was.

This is the code to circlize Phi:

```library(circlize)
library(scales)
factors = as.factor(0:9)
lines = 2000 #Number of lines to plot in the graph
alpha = 0.4  #Alpha for color lines
colors0=c(rgb(239,143,121, max=255), rgb(126,240,188, max=255), rgb(111,228,235, max=255),
rgb(127,209,249, max=255), rgb( 74,106,181, max=255), rgb(114,100,188, max=255),
rgb(181,116,234, max=255), rgb(226,135,228, max=255), rgb(239,136,192, max=255),
rgb(233,134,152, max=255))
#You can find the txt file here: http://www.goldennumber.net/wp-content/uploads/2012/06/Phi-To-100000-Places.txt
phi=gsub("\\.","", substr(phi,1,lines))
phi=gsub("\\.","", phi)
position=1/(nchar(phi)-1)
#This code generates a pdf file in your working directory
pdf(file="CirclizePhi.pdf", width=25, height=25)
circos.clear()
par(mar = c(1, 1, 1, 1), lwd = 0.1, cex = 0.7, bg=alpha("black", 1))
circos.par("cell.padding"=c(0.01,0.01), "track.height" = 0.025, "gap.degree" = 3)
circos.initialize(factors = factors, xlim = c(0, 1))
circos.trackPlotRegion(factors = factors, ylim = c(0, 1))
for (i in 0:9) {circos.updatePlotRegion(sector.index = as.character(i), bg.col = alpha("black", 1), bg.border=alpha(colors0[i+1], 1))}
for (i in 1:(nchar(phi)-1)) {
m=min(as.numeric(substr(phi, i, i)), as.numeric(substr(phi, i+1, i+1)))
M=max(as.numeric(substr(phi, i, i)), as.numeric(substr(phi, i+1, i+1)))
d=min((M-m),((m+10)-M))
col=t(col2rgb(colors0[(as.numeric(substr(phi, i, i))+1)]))
if (col>255) col=255;if (col>255) col=255;if (col>255) col=255
if (col<0) col=0;if (col<0) col=0;if (col<0) col=0 if (d>0) circos.link(substr(phi, i, i), position*(i-1), substr(phi, i+1, i+1), position*i, h = 0.1375*d+0.1125, lwd=0, col=alpha(rgb(col, max=255), alpha), rou = 0.92)
}
dev.off()
```

## 15 thoughts on “Maths, Music and Merkbar”

1. Big Data Doc says:

You are a real #Maths artist! always a pleasure reading your blog!

1. aschinchon says:

Wow!! Thanks a lot!

2. onehundredtwentythreedays says:

I barely function in R. This is impressive.

1. aschinchon says:

Thank you!

3. Aaron says:

Wonderful, but I”m getting the following error:

Error in if (d > 0) circos.link(substr(phi, i, i), position * (i – 1), :
missing value where TRUE/FALSE needed
1: NAs introduced by coercion
2: NAs introduced by coercion

Have any thoughts?
Thanks!

1. aschinchon says:

Thanks. I don’t get this error. Did you download the txt file with digits of phi?

1. Aaron says:

Yes, I did. I think the file was read OK because I can see the number for my phi value.

2. Noe versta says:

I had to change the following lines:
phi=gsub(“\.”,””, substr(phi,1,lines))
phi=gsub(“\.”,””, phi)

Now it works and gives a wonderful plot. Many thanks

4. dksam says:

Thanks, could reproduce the beautiful picture, awesome work, keep it up

5. Charles says:

I really enjoyed this! Thanks for posting!

6. Pbn says:

Mejor sintonizado con mis intereses, imposible: música electrónica, psicodélica, big-data, r. En las manos del maestro Chinchón. Extraordinario.

1. @aschinchon says:

Gracias!

7. Glenn says:

Thank you for your blog. Math is indeed beautiful! And you are a master in Art. I’m still a relative neophyte in R and enjoy using existing code to learn the language – after, of course, reading the intro books. (I needed to put a semicolon before the If (d>0) statement to get it to work.)