我试图在迭代地注释许多图。我希望注释在所有图上完全相同的位置出现,但是它们都具有不同的y轴尺度。如何在不使用Y值的情况下注释图表?必须有一种独立的方式,但我认为我缺少一个关键的词汇,因此我的搜索毫无结果。
通常,我会添加,例如, notate(“ text”,x = 5,y = 10)
到ggplot对象,但这是不起作用的,因为y的范围在组之间差异很大。
考虑到大约有30个地块可以跟踪,这是一个使用mtcars和ggpubr的玩具示例。
library(ggpubr)
ggboxplot(mtcars, x = "gear", y = "wt") +
annotate("text", x = 2, y = 5, label = "I should be in the same place in both plots")
ggboxplot(mtcars, x = "gear", y = "disp") +
annotate("text", x = 2, y = 5, label = "I should be in the same place in both plots")
I am trying to annotate many plots iteratively. I want an annotation to appear in the exact same place on all graphs, but they all have different y-axis scales. How do I annotate a graph without using the y-values? There must be a data-independent way, but I think I am missing a key piece of vocabulary so my searching has been fruitless.
Normally, I would add, e.g., annotate("text", x = 5, y = 10)
to the ggplot object, but this doesn't work because the range of y varies widely between groups.
Bearing in mind there are around 30 plots to keep track of, here is a toy example using mtcars and ggpubr.
library(ggpubr)
ggboxplot(mtcars, x = "gear", y = "wt") +
annotate("text", x = 2, y = 5, label = "I should be in the same place in both plots")
ggboxplot(mtcars, x = "gear", y = "disp") +
annotate("text", x = 2, y = 5, label = "I should be in the same place in both plots")


发布评论
评论(3)
您可以从
patchwork
中使用inset_element
来覆盖仅由彼此绘图的标签组成的绘图。
You could use
inset_element
frompatchwork
to overlay a plot consisting of just the label on top of each other plot.We could go one step further and define:
Then each plot could be:
开发第一个
y
by 100:Devide the first
y
by 100:您可以将轴最大值的一部分传递。
它并不总是使它们始终处于同一位置,但是它很近。
You can pass a percentage of the maximum value of the axis.
It doesn't get them always in the same spot but it gets pretty close.