使用多个标签手动注释一个面板 [英] Manually annotate one panel w/ multiple labels

查看:25
本文介绍了使用多个标签手动注释一个面板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这与这个问题非常相似(link),但我不太确定如何根据我的需要操作它.

This is very similar to this question (link), but I'm not quite sure how to manipulate it for my needs.

我有一个包含两个面板的多面图,我想在第一个面板中标记三个象限,并且只在第一个面板中标记.

I have a faceted plot with two panels, and I would like to label three quadrants in the first panel and only the first panel.

这是一个模拟数据集:

dfr=data.frame(
 variable=rep(c("A","B"),each=2),
 x=c(2,-3,4,-5),
 y=c(-2,4,-2,6))

这是情节:

p=ggplot(dfr,aes(x,y))+
 geom_point()+
 facet_grid(variable~.)+
 scale_x_continuous(limits=c(-6,6))+
 scale_y_continuous(limits=c(-6,6))+
 geom_hline(yintercept=0)+
 geom_vline(xintercept=0)

这是我想要完成的:

推荐答案

您始终可以使用所需标签创建单独的数据框,并使用 geom_text 绘制它们:

You can always create a separate data frame with the desired labels and plot them using geom_text:

dfLab <- data.frame(variable = rep("A",3),
                    x = c(3,3,-3),
                    y = c(3,-3,-3),
                    lab = c('I','IV','III'))


ggplot(dfr,aes(x,y))+
 geom_point()+
 facet_grid(variable~.)+
 scale_x_continuous(limits=c(-6,6))+
 scale_y_continuous(limits=c(-6,6))+
 geom_hline(yintercept=0)+
 geom_vline(xintercept=0) + 
 geom_text(data = dfLab,aes(x=x,y=y,label=lab))

这篇关于使用多个标签手动注释一个面板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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