我试图在ggplot2图中注释文本,将希腊字母与撇号和文本相结合。直到现在我无法实现这个探索。
现在,我可以编写以下标签,结合annotate和geom_text,这里是代码:
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")
结果在R ggplot2包中:
greek letter annotate without apostrophe
我尝试了不同的组合(将其声明为表达式,粘贴等,但我无法解决)。
我想在excel中获得这样的图,带有以下注释(带上标撇号和文本的phi):
excel plot with desired annotation
任何帮助都将受到高度赞赏!
提前致谢, 劳尔
答案 0 :(得分:2)
以下是示例图片:
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()