How to plot multiple data series in R?

plot multiple data series - Multiple plots in R

I usually use ggplot2 to plot multiple data series, but if I don’t use ggplot2, there are TWO simple ways to plot multiple data series in R. I’ll go over both today.

Matlab users can easily plot multiple data series in the same figure. They use hold on and plot the data series as usual. Every data series goes into the same plot until they use hold off.

But can the same thing be done in R? R is getting big as a programming language so plotting multiple data series in R should be trivial.

The R points and lines way

Solution 1: just plot one data series and then use the points or lines commands to plot the other data series in the same figure, creating the multiple data series plot:

> plot(time, series1, type='l', xlab='t /s', ylab='s1')
> points(time, series2, type='l')

Plot Multiple Data Series the Matlab way

Solution 2: this one mimics Matlab hold on/off behaviour. It uses the new parameter of graphical devices. Let’s see how:

Setting new to TRUE tells R NOT to clean the previous frame before drawing the new one. It’s a bit counter intuitive but R is saying “Hey, theres a new plot for the same figure so don’t erase whatever is there before plotting the new data series“.

Example (plot series2 on the same plot as series1):

> plot(time, series1, type='l', xlim=c(0.0,20.0), 
+ ylim=c(0.0,1.0), xlab='t /s', ylab='s1')
> par(new=T)
> plot(time, series2, type='l', xlim=c(0.0,20.0), 
+ ylim=c(0.0,1.0), xlab='', ylab='', axes=F)
> par(new=F)

The par(new=T) tells R to make the second plot without cleaning the first. Two things to consider though: in the second set axes to FALSE, and xlabel and ylabel to empty strings or in the final result you’ll see some overlapping and bleeding of the several labels and axes.

Finally, because of all this superimposing you need to know your axes ranges and set them up equally in all plot commands (xlim, and ylim in this example are set to the range [0,20] and [0,1]).

R doesn’t automatically adjust the axes, as it doesn’t use the first frame as reference or the multiple data series. You need to supply these values or you’ll end up with a wrong looking plot like Marge Simpson’s hair.

In conclusion, either solution will work to plot multiple data series inside R, but sometimes one will be better than the other. Sometimes your data series represent different properties and you’ll need to specify the y ranges individually. In this case the latter option might be useful. Other times you just want a quick exploratory data analysis plot, or your data series are measuring the same property and the former method suffices.

 

SimpleTask – O que faz, faz bem

Sou um adepto de pequenos utilitários para facilitar a nossa vida. E se no caso do Mac já analisei várias ferramentas para ajudar a organizar o dia a dia, a verdade é que no final há uma coisa que quase todos precisamos: Listas de coisas a fazer.

A minha última descoberta e agora parceiro predilecto da barra de menus chama-se SimpleTask. Simples, sem bling, e sempre à distância de um atalho. Experimentem!

AB testing webpage CSS

AB testing is one of the most talked optimisation strategies for webpages. Google made it very popular by optimising it thoroughly in their pages. It’s using crowd-source intelligence for website optimisation…

The basic idea of AB testing is that you have 2 alternative pages that you want to test and see which of the two performs the best. The notion of performance can be which of the two alternatives led to more sells, or more clicks, or what ever you want to convert to.

Then the analysis is just a matter of computing the statistical relevance of the difference of the two alternatives (a basic two-sample proportion test, or a two-sample Z-test, for those who want the maths).

Google provides a great tool to do Website Optimisation with AB testing (and Multi-variable testing), but the problem is that you can’t really do CSS testing with it (there are some ways around it but I don’t like them). For this I decided to roll out my own AB testing for CSS alone.

It uses Javascript to apply styles to the webpage as it loads and it stores cookies that will track information for the conversion part. My basic research question for my experiments with sixhat.net is “How do CSS styles affect people website usability?”. This is a simple question with lot’s of sub questions associated with it.

Here I’m using sixhat.net as my lab. It’s simply my blog and probably you have seen some natural changes over time, if you are a regular reader (that I appreciate). But some of the answers I get from my toy website are then translated to bigger projects (for example ASSYST received some inputs from the AB testing done here.)

If you come here sometimes and find that the website really looks strange, maybe its is because I’m testing something weird. Don’t worry, each test takes little time and everything will be back to “normal” in a couple of days (usually)!

Skype goes down the drain… the end for free-VOIP? Opportunities for Open-source?

Yesterday we had a not so shocking news about skype. It was bought by Microsoft. What does this mean to Skype? Well, from all the possible companies that could try to snatch Skype who could be worse?

I believe that Facebook comes to the idea. The biggest problem for Skype is that Microsoft (or Facebook) is not going to keep Skype running as it is (as its business model is flawed), and will try to strip it of the free parts and integrate it in their own products. My strongest bet is that Skype will be part of the Office suite to boost the collaborative part of office.

If Microsoft is to keep Skype available externally it will probably modify it to integrate its users into Office latter. The big problem here is that many Skype users aren’t office users and so the question is what Microsoft is going to do with those users? Microsoft can’t just make Skype another MSN bloated app. It was to expensive for that… Well, MS knows better than me how to spend money and destroy products (remember Hotmail?).

On the other hand, if Microsoft closes Skype completely inside Office, what will happen to VOIP? There are several free and open-source alternatives to Skype, but they don’t have the critical mass that Skype has, so Microsoft will need to manage this transition carefully as it might give opportunities to other companies to bump their opensource-VOIP solutions (taking notes, Canonical?).

Finally, at that price what has Microsoft really bought? Does Microsoft know that the important part of Skype IP is not owned by Skype?

My HTML to eReader process…

I’ve always tried to find the best way to move things from the Web/Computer to my eReader. I have an old eBook reader from BeBook and I always searched for the best workflow to have my stuff always with me in the BeBook. I have been asking for a HTML2ePub plugin or a Save As ePub option  in browsers for sometime, but until that day comes here is how to convert webpages to PDF for the ebook.

My first option was/is Calibre to do conversions. It uses recipes tailored for each website you want to download and converts them to the format you want (ePub, mobi, pdf, etc…). It’s easy, but you need to configure recipes and if the website doesn’t provide an RSS feed you have to code a lot in python.

My most recent approach is a little bit more elaborate, but I think the results are even better. It’s a multiple step process that involves different tools, but gets you wonderful reading experiences in the eBook reader. PDF, yes… I convert everything to PDF. But wait, there’s a trick. Here is how I do it:

1) Install the Readability bookmark/addon for your browser. Readability converts any webpage into a very beautiful and easy to read version.

2) Configure a page format in the printers preferences. Call it “BeBook”. The BeBook screen is 6” (9cm x 12cm) but I found that a page with 14cm x 17cm works best.

3) Print the Readability version of the webpage to a PDF file with this special page size.

4) As this PDF has some white margins (something that is totally nonsense for eBook readers) use Adobe Acrobat Pro to crop all white margins from the PDF file.

The final version reads perfectly in the eReader. The number os words per line is perfect and the font size is also great. The BeBook has two PDF rendering engines: Adobe and XPDF. While the first is more elegant, the second is much faster, but both engines produce great results. If you don’t like the pdf format you can then convert the pdf to epub.

Apple to move to ARM based computers?

I don’t really understand what apple does, but that’s probably why I never earned a dime on its stock. So as a disclaimer for the stop-by reader, I DON’T KNOW WHAT I’M TALKING ABOUT WHEN I TALK ABOUT APPLE! (it’s the same thing when I talk about sex, or so she tells me, don’t worry, it gets worse with age) .

After getting that out of the way, I was amused by today’s rumor that Apple is tinkering with the idea of switching to ARM in a couple of years. Switching, that’s something apple has done in the past few years. It is always a pain, requiring emulation layers (and things breaking up in the process), recompiling everything in the meanwhile, and forcing people to dump old machines quickly.

I doubt they will do it and switch to ARM, at least while Intel and AMD play strong in the chips war. If apple was to switch to ARM that would put off all those Mac users that are also Windows users. This alone made a big difference for people adopting the Mac, and I think that if Mac suddenly had a sticker saying “NO WINDOWS” it would reflect heavily on new mac sales.

Now, is it impossible? I don’t claim that apple couldn’t switch to ARM. They’ve bought PA Semi, so they have the know how. The problem is that they would need to come out with a monstrous Chip that could beat the crap out of Intel top end chips. That chip would need to be so powerful that people would be attracted by its sheer raw power.

The problem for this is that high throughput comes at the prices of a higher power requirements and that implies higher thermal envelopes and that implies bigger fans and dissipators and that… you see… these are all the things apple would need to add to their very thin, very elegant computers where they like to use low power cpus, etc, etc…

For all it is worth, my take on this is that this rumor is just vaporware to please stock owners. Intel and AMD are probably laughing about all this (although they might take clever measures in the background to avoid being surprised and cornered in the chips war).

SSD – When will the prices come down?

The price per Gig of SSD Drives is too high. I was reading about the performance gains of the MacBook / Pros reported by Macworld and couldn’t stop thinking why haven’t SSD thrown the old spinning HD to the history shelves? Usually when a new technology is so much better the the old one it just replaces the old one. Look at CDs and K7s for example, or MP3 based players vs CDs and vs Mini Disks. So, why aren’t SSD totally replacing HDs in computers? Are the prices being kept artificially high so companies can milk early adopters?

Wifi FON_ZON em HTTPS, EeePc e eReaders

Pequenas notas que se vão aprendendo em viagem:

Quase em todo o lado se encontram redes Wifi FON_ZON_INTERNET_FREE. Ora estas, permitem o acesso ao mundo Google sem que seja necessário pagar, utilizar o login da fonera, etc… o que é excelente para ver os emails, ler o reader e até fazer pesquisas na internet.

Isto já é coisa antiga (2008), mas parece que só eu é que não sabia.

O melhor no entanto é que também se pode ver outras coisas como o Youtube. Basta para isso forçar todos os endereços do Youtube a serem abertos em HTTPS e não HTTP. Cool.

Excelente para quando em viagem não tiver outro meio de acesso. Agora só me falta implementar um proxy em cima do Google para ter acesso a tudo utilizando o Google e eventualmente ao Bittorrent… Isso é que seria de génio.

Ainda no que diz respeito ao debate sobre o MacBook Air, posso dizer que o meu EeePC de há 3 anos continua a portar-se lindamente para viajar.

Hoje estava numa explanada e tinha o meu eBook reader pousado em cima da mesa. Posso dizer que chamou à atenção, mais até do que o iPad do miúdo da mesa do lado. Chamou principalmente por parte de quem quer ler livros electrónicos que já sabem o que é um eReader.