R Tip: ggplot axis labels

How to change the x and y axis labels in ggplot2?

For this example I’ll be using the movies dataset.


Traditionally the labels are set by ggplot directly from aesthetics selected e.g.:

p0<-ggplot(data=movies, aes(x=year))

plot of chunk ggplot-axis-01

To change the labels of the ggplot axes we can use xlab and ylab

p0+xlab('The glorious years of the movies')+ylab('The public ratings')

plot of chunk ggplot-axis-02

Another alternative is to define the axes labels when defining a scale for the plot e.g.:

  scale_x_continuous('The glorious years of the movies (with scales)')+
  scale_y_continuous('The public ratings (with scales)')

plot of chunk ggplot-axis-03

Also worth investigating is the labs function that allow the change of the axes and the title e.g.:

  x='The glorious years of the movies (with labs)',
  y='The public ratings (with labs)'

plot of chunk ggplot-axis-04

And what about formating the label text for size and rotation?

p0 + xlab('The Years of Cinema')+
  ylab('Public Ratings')+
    axis.text.x=element_text(angle=90, size=8),
    axis.title.x=element_text(angle=10, color='red'),
    axis.title.y=element_text(angle=80, color='blue', face='bold', size=14)

plot of chunk ggplot-axis-05

The formatting of the text in the labels is a bit counter intuitive because it uses a slightly different nomenclature. The formatting is done with the theme function and by defining element_text’s with the wanted format. In the example above the axis.text.x defines the ticks format and the axis.title.? define the labels format.

A good way to learn all the elements that a ggplot theme can format can be obtained from the help menu by entering ?theme. These examples are just scrapping the surface of what you can do.

Side Note: Did you noticed how crappy the movies from the 70s, 80s and 90s were?

  2014/08/18 2:47 PM

Siri’s Inventors Are Building a Radical New AI That Does Anything You Ask

The inventors of Siri are confident that their next creation will eclipse the first. But whether and when that will happen is a question that even Viv herself cannot answer. Yet.

via Siri’s Inventors Are Building a Radical New AI That Does Anything You Ask | Enterprise | WIRED.

Are we getting to the point of Her? Is this the Singularity? In any case AI is fun again!

  2014/08/17 12:39 PM

Is the singularity cost prohibitive?

The idea that a technological singularity is going to hit us any time in the future and that at that moment in time we’ll be presented with (now) unimaginable artificial intelligence (or at least greater than human intelligence, and that’s not saying much because on its own greater-than-human-intelligence is full of caveats) is a recurrent [...]

  2014/07/21 3:42 PM

How Educators Around The World Are Implementing Mobile Learning And What You Can Learn From Them

Still, UNESCO reports that 250 million students worldwide cannot read, write, or count, even after four years of school. Close to 775 million adults– 64% of whom are women–still lack reading and writing skills, with the lowest rates in Sub-Saharan Africa and South and West Asia.via How Educators Around The World Are Implementing Mobile Learning [...]

  2014/07/21 10:01 AM

Global Brain: Web as Self-organizing Distributed Intelligence – Francis Heylighen

OVERVIEW: Distributed intelligence is an ability to solve problems and process information that is not localized inside a single person or computer, but that emerges from the coordinated interactions between a large number of people and their technological extensions. The Internet and in particular the World-Wide Web form a nearly ideal substrate for the emergence [...]

  2014/07/18 9:02 AM

Os regulamentos da cidade islâmica

As leis islâmicas al-fikh abrangem a organização urbana das cidades islâmicas; não segue à risca as imposições de um plano, defende os interesses da família, e revela um modo autossuficiente de fazer cidade, sustentado por suas próprias leis. via arquitextos 169.04 oriente: Os regulamentos da cidade islâmica | vitruvius.

  2014/07/15 7:33 PM

Justin Reich on MOOCs and the Science of Learning

Millions of learners on platforms like edX and Coursera are generating terabytes of data tracking their activity in real time. Online learning platforms capture extraordinarily detailed records of student behavior, and now the challenge for researchers is to explore how these new datasets can be used to advance the science of learning. In this edX [...]

  2014/07/09 10:27 AM

As listas que para aí se fazem

Portugal é o país das listas, de apoio, de censura, para tudo e mais alguma coisa, até para se sair das listas é preciso subscrever outra. Um país de amorfos alistados.

  2014/07/07 6:04 PM

Why I gave up on Evernote

Evernote has been bon out of a great idea, but in the end didn’t evolve into anything special. Looks like a last decade application right now. It is dated in some aspects that one would think a modern note taking application should have Space and features. The basic free account limits are pre-historic for modern [...]

  2014/07/05 9:45 AM

Notas sobre futebol – o debacle Português no Brasil

Como todos os que viram o jogo da selecção Portuguesa contra a Alemanha, também tenho uma opinião que mais do que analítica é intuitiva. Certamente alguns concordarão com alguns dos meus pontos, alguns certamente discordarão. Ainda bem! AINDA (mesmo que alguns não gostem) é possível discordar neste país. Mais uma vez vi o Nani a [...]

  2014/06/17 4:33 PM

Pulley Logic Gates – Just Brilliant

Pulley Logic Gates from Alex Gorischek on Vimeo. Just come across this video of physical logic gates made with some a board, some string and weights. Just brilliant and instructive for any computer geek out there.

  2014/06/03 9:41 AM

Traversing News with Second Order Swarm Intelligence

Figure – Two simplicies a and b connected by the 2-dimensional face, the triangle {1;2;3}. In the analysis of the time-line of The Guardian newspaper (link) the system used feature vectors based on frequency of words and them computed similarity between documents based on those feature vectors. This is a purely statistical approach that requires [...]

  2014/05/28 6:16 PM

As eleições “para quê votar?”, dizem eles!

Há algo que me incomoda na forma como a direcção geral da administração interna decidiu não repetir as eleições nas freguesias que boicotaram no domingo com o argumento de que não iriam nunca afectar os resultados. Trata-se de um entendimento do acto eleitoral completamente obtuso, “que só serve para eleger políticos”, e nada mais. Votar [...]

  2014/05/27 9:46 AM

O Expresso Diário

O Expresso decidiu lançar um jornal novo, diário e vespertino. A verdade é que não passa de um embuste para cobrar mais por conteúdos, que são todos chamados a partir de uma app em JavaScript de forma a que os motores de busca os não possam ler e dessa forma não os possam indexar. A [...]

  2014/05/07 9:39 AM

Switching to Colemak (part 2)

After deciding to learn Colemak to improve my touch-typing speed in the beginning of the month, I decided to give you an update on my progress: After maybe one week I already knew the layout, but the speed was very slow, maybe 10wpm. This made it impossible to use it daily and therefore I kept [...]

  2014/04/23 10:17 AM

Switching to Colemak (part 1) – The reasoning

This is going to be probably the first part of a multi-part on my attempt to switch to the Colemak layout. Why Colemak? My reasoning to change keyboard layouts has to do with the amount of typing I really have to do every day. I can write consistently around 50-55 words per minute on a [...]

  2014/04/07 9:30 PM

The Conclusion in scientific papers?

“Here’s a simple test: if somebody reads your conclusions before reading the rest of your paper, will they fully understand them? If the answer is ‘yes’, there’s probably something wrong. A good conclusion says things that become significant after the paper has been read. A good conclusion gives perspective to sights that haven’t yet been [...]

  2014/04/05 3:21 PM