gpt4 book ai didi

r - 使用注释将不同的注释添加到不同的方面

转载 作者:行者123 更新时间:2023-12-03 12:45:38 25 4
gpt4 key购买 nike

我试图将面板标签添加到绘图中的不同方面。我希望它们是1:7,但是下面的代码

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)


产量

Error: When _setting_ aesthetics, they may only take one value. Problems: label


现在,我可以提供一个值并将其复制到所有方面。但是,如何使用anateate()在不同的方面具有不同的标签?

最佳答案

使用annotate,您不能。但是通过设置data.frame并将其用作geom_text的数据源,这很容易(有一些簿记方面)。

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)

关于r - 使用注释将不同的注释添加到不同的方面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11023129/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com