Crump, Ron
unread,Aug 21, 2015, 6:02:34 AM8/21/15Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ggp...@googlegroups.com
Hi,
Having a little problem getting expressions into my legend labels.
Here is some example data:
zz <- structure(list(x = c(1970L, 1971L, 1972L, 1973L, 1974L, 1975L,
1976L, 1977L, 1978L, 1979L, 1980L, 1970L, 1971L, 1972L, 1973L,
1974L, 1975L, 1976L, 1977L, 1978L, 1979L, 1980L, 1970L, 1971L,
1972L, 1973L, 1974L, 1975L, 1976L, 1977L, 1978L, 1979L, 1980L
), y = c(0.970143565209582, 0.425199685618281, 0.748703769175336,
0.749315701657906, 0.468444062629715, 0.994439253117889, 0.161479195114225,
0.536185430362821, 0.747455008327961, 0.0604149552527815,
0.183885730803013,
0.31202163011767, 0.707220257958397, 0.569816916249692, 0.640419519972056,
0.93991412059404, 0.116871100850403, 0.893233464099467, 0.831902656704187,
0.172733208630234, 0.265650319634005, 0.063512880820781, 0.426135629182681,
0.523865050170571, 0.632733916630968, 0.216925758402795, 0.20172484847717,
0.0342107121832669, 0.912192743737251, 0.988305125385523,
0.598734048428014,
0.0579233700409532, 0.482535298913717), z = structure(c(1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label =
c("a",
"b", "c"), class = "factor")), .Names = c("x", "y", "z"), row.names = c(NA,
-33L), class = "data.frame")
I¹d like to have "Measurement year, d² as the legend title, with a line
break between Measurement and year. This works in the example code below,
except that the gap between the comma and d is too big.
The legend labels should then indicate that: d < 1972, 1972 <= d < 1977
and d >= 1977. The second of these expressions, in which there is a <= and
a < is giving me difficulty. If just make it 1972 <= d it works, but
obviously isn¹t what I want to say.
The code is:
ggplot(zz,aes(x=x,y=y,colour=z))+geom_line()+
scale_colour_manual(values=c("red","blue","green"),name=expression(paste("M
easurement\nyear,",italic(d),sep="")),labels=expression(italic(d)<1972,1972
<= italic(d) < 1977, italic(d) >= 1977))
And gives the error:
Error: unexpected '<' in
"ggplot(zz,aes(x=x,y=y,colour=z))+geom_line()+scale_colour_manual(values=c(
"red","blue","green"),name=expression(paste("Measurement\nyear,",italic(d),
sep="")),labels=expression(italic(d)<1972,1²
If I put ³(1972 <= italic(d)),1977², the code runs but I get the extra
brackets.
So I¹ve got 2 little problems there: (a) spacing in the legend title and
(b) having a greater than or equals and a less than in the same expression.
My actual plot uses far more data and requires a number of these ³is
between² bits in the legend labels.
Thanks for your time,
Ron.