【发布时间】:2021-07-13 14:10:47
【问题描述】:
在本例中,统计文本的位置以“标准化父坐标”(NPC)给出:
ggplot2::ggplot(data.frame(x = c(2, 3, 4), y = c(2, 2.5, 4)),
aes(x = x, y = y)) +
ggplot2::coord_cartesian(xlim = c(1, 5), ylim = c(1, 5)) +
ggpubr::stat_cor(label.x.npc = 0, label.y.npc = 1)
但是,标签并不是像人们想象的那样从(1, 5) 开始(如果是父级的笛卡尔坐标系),而是从(2, 4) 开始,数据的限制。为什么呢? NPC中的父母由什么决定?
【问题讨论】:
-
对于vanilla ggplot2,父级是面板,所以是位置比例限制+扩展。在内部,ggplot2 使用
scales::rescale(your_data, to = c(0, 1), from = panel_limits)(伪代码)将数据转换为 npcs。不过我不知道 ggpubr 函数。
标签: r ggplot2 coordinates parent