使用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图中?

发布于 2018-05-21 12:20:05
这似乎有两个要点。第一种方法是创建一个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()

第二种选择是创建一个新的data frame and add that to the plot.,虽然这样做的优点是对点有更多的控制,但缺点是标记将需要额外的工作。
发布于 2018-05-21 12:59:39
一种可能是有一个列来标识您想要标记的点,在本例中是列“lab”,并说我想标记点一和三:
df <- data.frame(x=c(10,20,30), y=c(15,25,35), z=c(75,55,35), VALUE=c(1,2,3), lab=c("One", "", "Three"))然后,可以使用geom_text或geom_label来标记这些特定点,例如:
ggtern(df, aes(x, y, z, value = VALUE)) +
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_text(aes(label = lab), vjust=1)https://stackoverflow.com/questions/50441843
复制相似问题