Reputation: 1059
I am using ggplot to plot some data across 5 facets and I want to put some text that says "Delta = #" where Delta is the upper case math delta symbol and # is 1,2,3,4, or 5 based on which facet it is. Here is what I have:
annotate("text",x="baseline",y=75,label=paste(expression(Delta),"=",1:5))
My line of code works but it spells out Delta rather than giving me the Delta symbol. How can I get the math symbol?
Upvotes: 0
Views: 1545
Reputation: 77116
annotate()
will give you the same annotation on each facet, you should use geom_text()
instead, with a suitable data.frame to provide the mapping.
library(ggplot2)
ggplot(data.frame(f=1:2, lab = sprintf("Delta == %i", 1:2))) + facet_wrap(~f) +
geom_text(aes(label=lab), x=0, y=0, parse=TRUE)
Upvotes: 1
Reputation: 24272
Try this
df <- mtcars[2:6,]
ggplot(df, aes(mpg, disp))+
geom_point()+
annotate("text",df$mpg,df$disp,label=paste(("Delta * '=' *"), 1:5),
parse=TRUE, hjust = 1.1)
Upvotes: 3