gpt4 book ai didi

r - 如何将特定的标记点添加到 ggtern 图中?

转载 作者:行者123 更新时间:2023-12-05 07:33:43 25 4
gpt4 key购买 nike

对于 ggplot2,我通常希望能够像这样添加一个数据点,

ggtern(df, aes(X, Y, Z, value = VALUE), aes(x, y, z)) +
geom_point(aes(fill = VALUE), size = 2, stroke = 0, shape = 21) +
scale_fill_gradient(low = "red",high = "yellow", guide = F) +
scale_color_gradient(low = "red",high = "yellow", guide = F) +
geom_point(aes(x = 10, y = 10, z = 50), shape = 21)

但是,当使用 ggtern 包生成三元图时,它们被插入到错误的位置(参见示例图像)并出现以下警告:

Warning: Ignoring unknown aesthetics: z

这意味着 ggplot2 可能会尝试渲染点而不是 ggtern。如何将特定的标记点添加到 ggtern 图中?

Ternery plot with data point in wrong location

最佳答案

看来这主要有两点。首先是创建一个 annotation ,尽管这可能并不理想,因为它不像一个点那么精确。一个例子是,

ggtern() + 
annotate(geom = 'text',
x = c(0.5,1/3,0.0),
y = c(0.5,1/3,0.0),
z = c(0.0,1/3,1.0),
angle = c(0,30,60),
vjust = c(1.5,0.5,-0.5),
label = paste("Point",c("A","B","C")),
color = c("green","red",'blue')) +
theme_dark() +
theme_nomask()

enter image description here

第二个选项是创建一个新的 data frame and add that to the plot.虽然这样做的优点是可以更好地控制点,但缺点是标记需要额外的工作。

关于r - 如何将特定的标记点添加到 ggtern 图中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50441843/

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