Here's a self-contained example:
set.seed(3)
d <- expand.grid(Age=seq(20, 50, 10), Race=c("B","A","L"))
d$Rate <- d$Age/10 + rnorm(nrow(d))/2
delta <- rep(0, nrow(d))
delta[d$Race=="B"] <- 0.1
delta[d$Race=="A"] <- -0.1
d$Rate <- d$Rate + delta
d$Lower <- d$Rate-0.15
d$Upper <- d$Rate+0.15
d$N <- 5+rpois(nrow(d), 15)
p <- ggplot(d, aes(x=Age, y=Rate, group=Race, colour=Race))
p1 <- p+geom_line()+labs(title="MSM HIV+ Prevalence by Race x Age, 2004, 2008, 2011 NHBS LA")
# first graph fine
plot(p1)
p2 <- p1+geom_linerange(aes(ymin=Lower, ymax=Upper, size=2, alpha=0.5), position=position_jitter(h=0, w=0.5))+geom_point(aes(size=N))
# 2nd graph legends not so good
plot(p2)
# Could not get next one to work well
p3 <- p2+
geom_text(aes(x=0.5, y=1, label="Courtesy of TA Bingham. Not for redistribution.", colour="black"))+
geom_text(aes(x=0.5,y=0.9, label="Bars are exact 95% profile likilihood CI's.", colour="black"))
plot(p3)
On 5/16/2013 12:18 PM, Ito, Kaori (Groton) wrote:
> Dear Ross,
> Could you provide the dataset (NHBS) so that we can see what is going on? Or, could you provide any toy example dataset which able to mimic your problem? It is hard to understand the problem unless seeing the plots....
> Kaori
>
> -----Original Message-----
> From:
ggp...@googlegroups.com [mailto:
ggp...@googlegroups.com] On Behalf Of Ross Boylan
> Sent: Thursday, May 16, 2013 3:09 PM
> To:
ggp...@googlegroups.com
> Subject: Controlling legends and annotations
>
> I'm having trouble controlling legends and adding annotations to some
> graphs:
> [snip]