我只想在放大区域对图表进行注释,以提供有关突出显示的数据的详细信息。
在下面的示例代码中,其思想是仅在放大区域中显示文本"zoom only“。
require(ggplot2)
require(ggforce)
ggplot(iris, aes(Petal.Length, Petal.Width, colour = Species)) +
geom_point() +
facet_zoom(x = Species == "versicolor") +
annotate("text", x=4, y=2, label="zoom only")缩放时仅显示文本(预期状态):

两种状态下的文本(当前状态):

有没有办法做到这一点?
发布于 2017-10-02 23:27:35
我们可以深入研究对象,并将文本设置为透明(alpha = 0):
p <- ggplot(iris, aes(Petal.Length, Petal.Width, colour = Species)) +
geom_point() +
facet_zoom(x = Species == "versicolor") +
annotate("text", x=4, y=2, label="zoom only")
pb <- ggplot_build(p)
pb$data[[2]][1, 'alpha'] <- 0
pg <- ggplot_gtable(pb)
plot(pg)

https://stackoverflow.com/questions/46496131
复制相似问题