Thanks in advance
Andreas
fil <- read.csv2("http://wana.dk/wp-content/uploads/2009/10/verdensdele.csv",,header=F,encoding="latin1",na.strings=0)
names(fil) <- c("status", "verdensdel", 1996:2008)
levels(fil$status) <- c("Andet grundlag", "Arbejdstilladelser",
"EF/EØS opholdstilladelser", "Familiesammenføring ægtefælle",
"Familiesammenføring anden familie", "Familiesammenføring børn",
"Flygninge", "Øvrige grunde", "Uddannelse")
library(ggplot2)
fil.m <- melt(fil,id.vars=c("status", "verdensdel"))
ren.fil.m <- subset(fil.m, verdensdel != c("Danmark", "Uoplyst"))
library(gdata)
ren.fil.m <- drop.levels(ren.fil.m)
p <- ggplot(ren.fil.m,
aes(x=variable,y=value,col=verdensdel,group=verdensdel,linetype=verdensdel,drop=T))+
geom_line()+
geom_point(size=2)+
scale_x_discrete("År", breaks=seq(1996,2008, 2))+
scale_y_continuous("Antal")+
geom_vline(aes(xintercept="2001", alpha=0.5,labels="Regering AFR"))+
opts(axis.text.x=theme_text(angle=90,hjust=1,size=8))+
# opts(legend.position="bottom")+
facet_wrap( ~ status, scales="free_y")+
opts(strip.text.x = theme_text(size = 8,colour = "black"))
Yes, that's a bug on my to do list.
> also I'd like to get a better legend label for
> the vline. How could I achieve this - labels does not seem to work?
You want (i.e. no aes, since you're not mapping variables in the
dataset to aesthetics)
geom_vline(xintercept="2001", alpha=0.5,labels="Regering AFR")
> Also the the "År" labels looks funny. It looks like 1996 and 1998 uses
> a smaller type then 2000, 2002, etc.?
Looks ok to me.
Hadley
I see the "smaller font" on 1996 and 1998, but I think it's just a
kerning issue (ie 1 is thinner than 2). If you make the graph thinner
so that they are right next to each other you'll see that the other
three numbers line up right, it's almost as if the number 1 is in the
'right-hand side' of the character position, this is very unlikely to
be something that ggplot2 is causing, most likely a font issue.
Of course the År label looks funny; it has one of those funny circles
on top of the letter! (Which is to say, not sure that poor english
writers have enough experience with these type of characters to know
what funny means in this context; the capital does look substantially
higher than the smaller case letter, looks like the font doesn't
adjust the height of the capitalized letters when adding diacriticals,
again probably a font issue. Try a different font?)
This is a good looking graph, btw (although you probably want to drop
the 0.5 legend, move alpha=0.5 outside the call to aes in geom_vline).
--J