Skip to content
Prev 179534 / 398502 Next

Bumps chart in R

(cross posting to the ggplot2 group for posterity)

Here's how I'd approach it:

library(ggplot2)
text = letters[1:20]
tal1 = rnorm (20,5,2)
tal2 = rnorm (20,6,3)
dif = tal2-tal1
df0 = data.frame(text,tal1,tal2)
df = melt(
	data = df0
	, id.vars = 'text'
	, variable_name = 'tal'
)
df$dif = dif
df$col = ifelse(dif>0,'red',ifelse(dif<0,'blue','black'))
df$size = abs(dif)

# draw the plot
ggplot(
	data=df
	, aes(
		x=tal
		, y=value
		, group=text
	)
) +
geom_line(
	aes(
		size=size
		, colour=col
	)
)+
geom_text(
	aes(
		label=text
	)
)+
opts(
	legend.position="none"
)+
theme_bw()


Unfortunately it's not perfect:
(1) col isn't being interpreted literally, so instead of truly red & blue.
(2) the lines ends are square whereas usually they're rounded.
(3) attempting to remove the legend via opts(legend.position="none")
seems to fail.

On Wed, May 6, 2009 at 6:44 PM, Andreas Christoffersen
<achristoffersen at gmail.com> wrote: