Raül Oo
Raül Oo

Reputation: 67

R annotate greek letter with apostrophe and text

I am trying to annotate text in a ggplot2 plot combining greek letter with apostrophe and text. Till now I am not able to achieve the probem.

For now, I can write the following label, combining annotate and geom_text, here is the code:

ggplot(Lab_all_direct_shear)+
    geom_rect(aes(xmin = 0, xmax = 20, ymin = 0, ymax = 120), color = NA, fill="grey", alpha = 0.05)+
    geom_segment(linetype = 8,color="#666666",aes(x = 0, y = 0, xend = 55, yend = 88.649))+
    geom_point(size=3,shape=21,fill ="#F8766D",aes(x=constitutive_normal_stress_15_kPa,y=constant_volume_shear_strenght_15_kPa))+
    geom_point(size=3,shape=21,fill ="#00BA38",aes(x=constitutive_normal_stress_19_kPa,y=constant_volume_shear_strenght_19_kPa))+
    geom_point(size=3,shape=21,fill ="#619CFF",aes(x=constitutive_normal_stress_25_kPa,y=constant_volume_shear_strenght_25_kPa))+
    scale_x_continuous(limits = c(0,60),breaks=c(0,10,20,30,40,50,60),expand = c(0, 0)) +
    scale_y_continuous(limits = c(0,120), breaks=c(0,10,20,30,40,50,60,70,80,90,100,110,120),expand = c(0, 0)) +
    labs(x=expression(~sigma[n]~+~s~S[r]~(kPa)),y = "",title="") +
    annotate("text", x = 54, y = 70, label = "= 58.2°",size=4)+
    geom_text(x=50,y=70,label="phi",parse=TRUE)+
    theme_bw() +
    theme(plot.title = element_text(size=10, face="bold", hjust=0.5),
            axis.title = element_text(size=10),
            axis.title.x = element_text(angle=0, hjust=0.5),
            axis.title.y = element_blank(),
            axis.text = element_text(size=10,color="black"),
            axis.text.x = element_text(size=10),
            axis.text.y = element_blank(),
            panel.grid.major = element_line(color= NA),
            panel.grid.minor = element_line(color= NA),
            plot.margin=unit(c(0.1,0.2,0.1,0.4), "cm"), #The four numbers are c(top,right,bottom,left)
            legend.text = element_text(size=10),
            legend.title = element_text(size=10),
            legend.position = "none")

And the result in R ggplot2 package:

greek letter annotate without apostrophe

I have tried different combinations (declaring it as expression, paste, etc, but I am not able to solve it).

I would like to obtain a plot like this in excel, with the following annotation (phi with superscript apostrophe in combination with text):

excel plot with desired annotation

Any help will be highly appreciated!

Thanks in advance, Raül

Upvotes: 2

Views: 936

Answers (1)

xiaojia zhang
xiaojia zhang

Reputation: 1058

Here's a sample image:

look at this sample picture

    data <- data.frame(x = 1:10, y  = 1:10)
    ggplot(data, aes(x, y))+
      geom_point(color = "blue")+
      geom_line(linetype = "dashed", color = "blue")+
      annotate("text", x = 6, y = 7, label  = "phi*' \\''==58^o",
               parse = TRUE)+
      theme_bw()

Upvotes: 3

Related Questions