它看起来像是ggtern还没有与新版本的ggplot2同步。因此我们不能使用ggtern。
library(ggtern)
set.seed(1)
plot <- ggtern(data = data.frame(x = runif(100),
y = runif(100),
z = runif(100)),
aes(x, y, z))
plot + stat_density_tern(geom = 'polygon',
n = 200,
aes(fill = ..level..,
alpha = ..level..)) +
geom_point() +
theme_rgbw() +
labs(title = "Example Density/Contour Plot") +
scale_fill_gradient(low = "blue",high = "red") +
guides(color = "none", fill = "none", alpha = "none")Error: geom_point requires the following missing aesthetics: x and y除了R中的ggtern之外,还有没有人可以找到三元图的其他选择呢?
发布于 2021-07-12 17:20:15
您可以使用函数手动绘制这些点:(我在https://en.wikipedia.org/wiki/Ternary_plot中使用了公式)
我不熟悉stat_density_tern的输出,所以我不确定从那部分能得到什么。
library(tidyverse)
tern <- function(df) {
df %>% mutate(x_pos = 0.5 * (2*y + z) / (x+y+z),
y_pos = sqrt(3) / 2 * z / (x+y+z))
}
tern(plot) %>%
ggplot(aes(x_pos, y_pos)) +
geom_point() +
annotate("path", x = c(0, 0.5, 1, 0), y = c(0,sqrt(3)/2,0,0)) +
coord_equal()

发布于 2021-07-20 16:44:27
这对我很有效!卸载ggtern和ggplot2,然后
install_version("ggplot2", version = "3.3.0", repos = "http://cran.us.r-project.org")
install.packages("ggtern")
library(ggtern)https://stackoverflow.com/questions/68344404
复制相似问题