Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 手动注释一个面板和多个标签_R_Annotations_Ggplot2 - Fatal编程技术网

R 手动注释一个面板和多个标签

R 手动注释一个面板和多个标签,r,annotations,ggplot2,R,Annotations,Ggplot2,这与这个问题()非常相似,但我不太确定如何根据我的需要处理它 我有一个有两个面板的平面图,我想在第一个面板中标记三个象限,并且只标记第一个面板 以下是模拟数据集: 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_con

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

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

以下是模拟数据集:

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
进行打印:

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

dfLab D'oh,这是我代码中的一个错误,我现在觉得自己很愚蠢。谢谢你的回答!