¿如何在R?
中的bquote()表达式中打印±符号我尝试了以下内容:
pm
%pm%
±
这些都没有用。
更新#1以下是一些示例代码
plot(NULL,xlim=c(0,10),ylim=c(0,10),xlab=NA,ylab=NA,xaxs="i",yaxs="i") c <- "name" p <- .004 n <- 969 b <- 1.23 s <- 0.45 tmp.txt <- paste(c(c," (n=",n,")\nslope = ",b,"±",s,"\n",ifelse(p==0,"p<.001",paste0("p=",p))),collapse="") text(9.5,9.5,labels=tmp.txt,adj=c(1,1),cex=.75)
我要做的是让第二行有beta(符号)而不是斜率,并出现±符号。如果我使用表达式,我可以获得beta,但不是±;如果我只是粘贴ß(或类似的东西),它将无法运行。
更新#2:看来我已使用bquote()...否则,当通过pdf()传出时,不会打印测试角色。
答案 0 :(得分:2)
对this question的回答建议将paste
与bquote
一起使用。然后,您可以使用±:
x <- 232323
plot(1:10, main = bquote(paste(ARL[1], " curve for ", S^2, "; x=\U00B1",.(x))))
请注意,此示例(减去包含\ U00B1)来自fabian对之前链接问题的回答。
答案 1 :(得分:0)
我很欣赏给出的建议,但它没有完全实现我的目标。这是我提出的解决方法(我个人认为它只是缺乏asinine ......但我不知所措。)
c <- "name" p <- .004 n <- 969 b <- 1.23 s <- 0.45 ## draw empty plot plot(NULL,xlim=c(0,10),ylim=c(0,10),xlab=NA,ylab=NA,xaxs="i",yaxs="i") ## place the "poor man's substitute" tmp.txt <- paste(c(c," (n=",n,")\nslope = ",b,"±",s,"\n",ifelse(p==0,"p<.001",paste0("p=",p))),collapse="") text(9.5,9.5,labels=tmp.txt,adj=c(1,1),cex=.75) ## place the next best option tmp.txt <- paste(c(c," (n=",n,")\n\U03B2 = ",b,"±",s,"\n",ifelse(p==0,"p<.001",paste0("p=",p))),collapse="") text(9.5,7.5,labels=tmp.txt,adj=c(1,1),cex=.75) ## place the two boxes to superimpose the bquote() version tmp.txt2 <- paste(c(c," (n=",n,")\n\n",ifelse(p==0,"p<.001",paste0("p=",p))),collapse="") text(9.5,5.5,labels=tmp.txt2,adj=c(1,0.5),cex=.75) text(9.5,5.5,labels=bquote(beta == .(b)%+-%.(s)),adj=c(1,0.5,cex=.75)) ## same as above, but piped to a *.pdf pdf("tmp_output.pdf") plot(NULL,xlim=c(0,10),ylim=c(0,10),xlab=NA,ylab=NA,xaxs="i",yaxs="i") tmp.txt <- paste(c(c," (n=",n,")\nslope = ",b,"±",s,"\n",ifelse(p==0,"p<.001",paste0("p=",p))),collapse="") text(9.5,9.5,labels=tmp.txt,adj=c(1,1),cex=.75) tmp.txt <- paste(c(c," (n=",n,")\n\U03B2 = ",b,"±",s,"\n",ifelse(p==0,"p<.001",paste0("p=",p))),collapse="") text(9.5,7.5,labels=tmp.txt,adj=c(1,1),cex=.75) tmp.txt2 <- paste(c(c," (n=",n,")\n\n",ifelse(p==0,"p<.001",paste0("p=",p))),collapse="") text(9.5,5.5,labels=tmp.txt2,adj=c(1,0.5),cex=.75) text(9.5,5.5,labels=bquote(beta == .(b)%+-%.(s)),adj=c(1,0.5,cex=.75)) dev.off()
如果你运行它,它似乎在R内部和生成的* .pdf文件中都有效。
与往常一样,一个更优雅(和明智)的解决方案将非常受欢迎。