带有draw_label

时间:2019-06-28 11:39:17

标签: superscript

我想做一个“简单”的事情。我想用一些统计信息来注释一个图。

  cor<-cor.test(PB.reg@data$x,PB.reg@data$y, method = "pearson")
  label<-(paste("Passing Bablok Regression (n =", length(PB.reg@data$x),")",sep=""))
  label2<-(paste("y = ", PB.reg@para[1,1], " + ",PB.reg@para[2,1], " * Method 1",  sep=""))
  label3<-(paste("R^2 = ",round(cor$estimate^2,3),sep="" ))

  p<-ggplot(subset) +
    aes(x = Rater_Mean, y = Smartphone_Mean, colour = Participant, label=Participant) +
    geom_point(size = 2) +
    scale_color_viridis_d(option = "inferno", alpha=0.8, direction=-1) +
    theme_classic()+
    geom_abline(intercept = PB.reg@para[1,1], slope = PB.reg@para[2,1],colour ="black", size=1, alpha=0.4)+
    geom_abline(intercept = PB.reg@para[1,3], slope = PB.reg@para[2,3],colour ="#2c718e",linetype="dotted")+
    geom_abline(intercept = PB.reg@para[1,4], slope = PB.reg@para[2,4],colour ="#2c718e",linetype="dotted")+
    geom_abline(intercept = 0, slope = 1, linetype="dotted", color="red")
    #geom_abline(intercept=seq(PB.reg@para[1,3],PB.reg@para[1,1],0.01), slope=PB.reg@para[2,3], alpha=0.2)+ #abline für LCI
    #geom_abline(intercept=seq(PB.reg@para[1,4],PB.reg@para[1,1],0.01), slope=PB.reg@para[2,4], alpha=0.2) #abline für UCI

  p<-p+
    ggtitle("Method 1 vs Method 2")+
    labs(x = "Method 1 [ms]", y = "Method 2 [ms]", title = "Method 1 vs Method 2")+
    theme(text = element_text(size = 16),axis.text = element_text(size = 12),plot.title = element_text(hjust = 0.5))



  ggdraw(p) + draw_label(label, .75, .2, size=12)+draw_label(label2, .75, .18,size=12)+draw_label(parse(text=lb1,keep.source = getOption("keep.source")), .75, .16,size=12)

enter image description here

您可以说...。我已经做到了,可以在右下角进行注释。现在,我正在为R ^ 2奋斗。 1)如何获得数学上正确的上标? 2)是否可以将所有draw_labels左右对齐?

1 个答案:

答案 0 :(得分:0)

bquote(R^2 == .(round(cor$estimate^2,3)))