[R] Bumps chart in R
Andreas Christoffersen
achristoffersen at gmail.com
Thu May 7 12:21:41 CEST 2009
On Thu, May 7, 2009 at 2:15 AM, Mike Lawrence <Mike.Lawrence at dal.ca> wrote:
> (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
>
> 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.
>
Thank you
with your melted data I was able to come very close to what I want.
legen.posistion="none" works for me... Annonying that colours don't
work like expected... It seams to be a frequent concern.
My code:
qplot(tal,value,data=df,group=text,geom="line",size=size,colour=col,xlab="Change
from time to time", ylab = "Points")+
geom_text(aes(label=text),subset(df,tal=="tal1"),size=3,hjust=2,vjust=0)+
theme_bw()+ opts(legend.position="none")+ opts(title="As time went
by") +opts(plot.title=theme_text(vjust=0,size=20))
More information about the R-help
mailing list