r - Insert accented arbitrary characters into ggplot legend -


i'd insert letter ^ symbol above letter ggplot title, e.g. p-hat (but formated).

i've tried:

x <- seq(1:6) y <- x^2 z <- rep(c("theta","gamma"),3) xyz <- data.frame(x,y,z)  ggplot(xyz, aes(x=x, y=y)) +    geom_point(aes(colour=z)) +    guides(colour = guide_legend(expression(p-hat))) 

but labels literally.

can't clear glossary or info on how in general accent arbitrary roman characters r plots, other specific characters used in e.g. french or spanish. thoughts?

r plotmath has both hat , widehat function. if wanted move annotation on right can use may tildes needed

x <- seq(1:6) y <- x^2 z <- rep(c("theta","gamma"),3) xyz <- data.frame(x,y,z)  ggplot(xyz, aes(x=x, y=y)) +    geom_point(aes(colour=z)) +    guides(colour = guide_legend(expression( hat(p) )))  ggplot(xyz, aes(x=x, y=y)) +    geom_point(aes(colour=z)) +    guides(colour = guide_legend(expression( widehat(p) )))  ggplot(xyz, aes(x=x, y=y)) +    geom_point(aes(colour=z)) +    guides(colour = guide_legend(expression( ~~~~~~~widehat(p) ))) 

see ?plotmath


Comments