我正在注释分面图以包含上标,但无法将文本设为粗体。我意识到这与创建 expression
有关。在绘图调用之外,然后指定 parse=TRUE
.可能有一个非常简单的解决方案,但到目前为止我尝试过的任何方法都没有奏效,包括使用 bquote()
和 bold()
.谢谢
library(ggplot2)
data(iris)
rsq<-c(.3,.6,.75)
pos<-c(5,6,7)
Species<-levels(iris$Species)
big_data<-as.data.frame(cbind(pos, rsq))
big_data$Species<-Species
lab <- paste("r^2 == ", round(big_data$rsq,2))
ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width)) +
facet_wrap(~Species,scales='free_x')+
geom_point(size=3,show.legend = F) +
geom_text(aes(x=pos,y=1,label=as.character(lab)),parse=TRUE,data=big_data,fontface='bold')
最佳答案
您可以获得r
成为 bold()
lab <- sprintf("bold(r)^2 == %.2f", big_data$rsq)
但仅此而已。来自
?plotmath
Note that bold, italic and bolditalic do not apply to symbols, and hence not to the Greek symbols such as mu which are displayed in the symbol font. They also do not apply to numeric constants.
更好的排版最好的选择可能是 tikzDevice。
关于r - 当 parse=TRUE 时将 geom_text 更改为粗体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43728261/