当parse = TRUE时,将geom_text更改为粗体 [英] Change geom_text to bold when parse=TRUE

查看:587
本文介绍了当parse = TRUE时,将geom_text更改为粗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在注释多面图以包括上标,但是在使文本变为粗体时遇到了麻烦.我意识到这与在绘图调用之外创建expression然后指定parse=TRUE有关.可能有一个非常简单的解决方案,但到目前为止,我尝试过的任何方法都没有奏效,包括使用bquote()bold().谢谢

I am annotating faceted plots to include a superscript, yet am having trouble making the text bold. I realise that this has something to do with creating an expression outside the plot call and then specifying parse=TRUE. There is probably quite a simple solution but so far nothing I have tried has worked, including the use of bquote() and bold(). Thanks

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')

推荐答案

作弊-将文本绘制3次,但大小略有增加.

A little cheat - over plotting the text 3 times with slight increases in size.

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,size=4)+
  geom_text(aes(x=pos,y=1,label=as.character(lab)),parse=TRUE,data=big_data,size=4.07)+
  geom_text(aes(x=pos,y=1,label=as.character(lab)),parse=TRUE,data=big_data,size=4.08)

这篇关于当parse = TRUE时,将geom_text更改为粗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆