使用注释将不同的注释添加到不同的构面 [英] Using annotate to add different annotations to different facets
本文介绍了使用注释将不同的注释添加到不同的构面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图将面板标签添加到情节中的不同方面。我想他们是1:7,但是,下面的代码
d < - ggplot(diamonds,aes(carat, (0,2)+ stat_binhex(na.rm = TRUE)+ opts(aspect.ratio = 1)
d1 < -d + facet_wrap(〜color)
d1 + annotate(text,x = 0.25,y = 1.5e + 04,label = 1:7)
产生
错误:当设定美学,他们只能拿一个价值。问题:标签
现在,我可以提供单个值并在所有方面进行复制。但是,如何使用annotate()在不同的方面使用不同的标签?
使用注释
code>,你不能。但通过设置 data.frame
并将其用作 geom_text
的数据源,很容易 d1 + geom_text(data = data.frame(x = 0.25,y = 1.5e + 04) ,标签= 1:7,
color = c(D,E,F,G,H,I,J)),
aes (x,y,label = label),inherit.aes = FALSE)
I'm trying to add panel labels to different facets in a plot. I want them to be 1:7, but, the following code
d <- ggplot(diamonds, aes(carat, price, fill = ..density..)) +
xlim(0, 2) + stat_binhex(na.rm = TRUE) + opts(aspect.ratio = 1)
d1<-d + facet_wrap(~ color)
d1+annotate("text", x=0.25, y=1.5e+04, label=1:7)
yields
Error: When _setting_ aesthetics, they may only take one value. Problems: label
Now, I can supply a single value and get that replicated across all facets. But how can I have different labels in different facets using annotate()?
解决方案
With annotate
, you can't. But by setting up a data.frame
and using it as the data source for a geom_text
, it is easy (with a few bookkeeping aspects).
d1 + geom_text(data=data.frame(x=0.25, y=1.5e+04, label=1:7,
color=c("D","E","F","G","H","I","J")),
aes(x,y,label=label), inherit.aes=FALSE)
这篇关于使用注释将不同的注释添加到不同的构面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文