[R] Bumps chart in R

Andreas Christoffersen achristoffersen at gmail.com
Mon Apr 27 11:14:52 CEST 2009


On Mon, Apr 27, 2009 at 2:23 AM, Mike Lawrence <Mike.Lawrence at dal.ca> wrote:
> Here's a ggplot2 based solution:

Wauw - thank you. I'm sure I need to understand gplot better. With
qplot I can make something similar - quite easy.

With your reformattet data:

#here's the data provided by Andreas
countries <- c("U-lande", "Afrika syd for sahara", "Europa og
Centralasien", "Lantinamerika og Caribien","Mellemøstenog
Nordafrika","Sydasien","ØStasien og stillehaveet", "Kina",
"Brasilien")
poor_1990 <- c(28.7,46.7,0.5,10.2,2.3,43,29.8,33,14)
poor_2004 <- c(18.1,41.1,0.9,8.6,1.5,30.8,9.1,9.9,7.5)

#reformat the data
data = data.frame(countries,poor_1990,poor_2004)
data = melt(data,id=c('countries'),variable_name='year')
levels(data$year) = c('1990','2004')

#make a new column to make the text justification easier
data$hjust = 1-(as.numeric(data$year)-1)

library(ggplot2)
qplot(year,value, data=data,label=countries, geom=c("line","text"),
group=countries, col=countries)

But I would like to have the text labels show only once - e.g. at 1990
- and also control the size of the text. In my crude qplot, setting
size=2 e.g. changes not only the text, but also the lines etc. I guess
I have to move from qplot to gplot.




More information about the R-help mailing list