将文本添加到ggplot中的单个构面 [英] Add text to individual facets in ggplot

查看:166
本文介绍了将文本添加到ggplot中的单个构面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道我是如何将不同的文本放在各个方面的。我想使用注解 geom_text()来添加文本 code>我知道这里有重复的帖子,但我没有设法让它正确。这里是我的数据:

 实验FC配对
Meister et al。 -2.74236520是
Meister等人。 -0.7436354 no
Meister et al。 -2.74236520是
Meister等人。 -0.73536354 no
daub et al。 -0.64246768是
daub et al。 -0.6663321 no
daub et al。 -0.64246768是
daub et al。 -0.6663321 no
hans et al。 -2.32230716是
hans et al。 -0.49423279 no
hans et al。 -2.32723716是
hans et al。 -0.4944279 no

ggplot(combined_pos1,aes(Pairing,FC,fill = as.factor(Pairing)))+
geom_boxplot(fill =grey90)+ coord_cartesian(ylim = c (-3,3))+
facet_grid(〜Experiment)


解决方案

创建每个方面的注释(这里以Meister和Hans为例):

  combined_pos1 $ annotations = c(Meister的文本,rep(,10),hans的文本)

include geom_text:

  g = ggplot(combined_pos1,aes(Pairing,FC,fill = as.factor(Pairing)) )+ geom_boxplot(fill =grey90)+ coord_cartesian(ylim = c(-3,3))+ facet_grid(〜Experiment)
g = g + geom_text(aes(x = 2.5,y = 2.5,label =注释))
g

这会产生以下结果:


I wonder how I put different text in individual facets. I want to add the text inside the plot using annotate or geom_text() I know there are duplicated posts in this, but I don't manage to get it correct. Here is my data:

Experiment         FC           Pairing
Meister et al. -2.74236520      yes
Meister et al. -0.7436354       no
Meister et al. -2.74236520      yes
Meister et al. -0.73536354      no
daub et al.    -0.64246768      yes
daub et al.    -0.6663321       no
daub et al.    -0.64246768      yes
daub et al.    -0.6663321       no
hans et al.    -2.32230716      yes
hans et al.    -0.49423279      no
hans et al.    -2.32723716      yes
hans et al.    -0.4944279       no

ggplot(combined_pos1,aes(Pairing,FC,fill=as.factor(Pairing))) + 
      geom_boxplot(fill = "grey90") +  coord_cartesian(ylim=c(-3,3)) + 
      facet_grid(~Experiment)

解决方案

create the annotations for each facet (here as an example for Meister and Hans):

combined_pos1$annotations = c("Text for Meister",rep("",10),"Text for hans")

include geom_text:

g = ggplot(combined_pos1,aes(Pairing,FC,fill=as.factor(Pairing))) + geom_boxplot(fill = "grey90") +  coord_cartesian(ylim=c(-3,3)) + facet_grid(~Experiment)
g = g + geom_text(aes(x=2.5,y=2.5,label=annotations))
g

This yields the following:

这篇关于将文本添加到ggplot中的单个构面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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