ggplot2:geom_text()与facet_grid()? [英] ggplot2: geom_text() with facet_grid()?

查看:144
本文介绍了ggplot2:geom_text()与facet_grid()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想为由ggplot2生成的每个图形面板添加注释; (a),(b),(c)等简单的标签。有没有简单的方法来做到这一点?

解决方案

From: https://groups.google.com/forum/?fromgroups=#!topic/ggplot2/RL8M7Ut5EpU 您可以使用以下内容:

  library(ggplot2)
x <-runif(9,0,125)
data < - as.data.frame(x)
data $ y < - runif(9,0,125)
data $ yy < - factor(c(a,b ,c))

ggplot(data,aes(x,y))+
geom_point(shape = 2)+
facet_grid(〜yy)+
geom_text(aes(x,y,label = lab),
data = data.frame(x = 60,y = Inf,lab = c(this,is,the way),
yy = letters [1:3]),vjust = 1)

你这个:


I just want to add annotation to each panel of figures generated by ggplot2; just simple labels like (a), (b), (c), etc. in each corner. Is there a simple way to do this?

解决方案

From: https://groups.google.com/forum/?fromgroups=#!topic/ggplot2/RL8M7Ut5EpU you can use the following:

library(ggplot2) 
x <-runif(9, 0, 125) 
data <- as.data.frame(x) 
data$y <- runif(9, 0, 125) 
data$yy <- factor(c("a","b","c")) 

ggplot(data, aes(x, y)) + 
    geom_point(shape = 2) + 
    facet_grid(~yy) + 
    geom_text(aes(x, y, label=lab),
        data=data.frame(x=60, y=Inf, lab=c("this","is","the way"),
             yy=letters[1:3]), vjust=1)

which should give you this:

这篇关于ggplot2:geom_text()与facet_grid()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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