2011-08-15 22 views
3

这与此问题非常相似(link),但我不太清楚如何操作它以满足我的需求。手动注释一个面板w /多个标签

我有两个面板的多面情节,我想在第一个面板和第一个面板中标出三个象限。

这是一个模拟数据集:

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) 

这是我想达到什么:

enter image description here

回答

4

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

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

enter image description here

+0

D'哦,那是在我的代码中的错误,现在我觉得自己很蠢。感谢您回答所有相同的问题! – jslefche