gpt4 book ai didi

r - 三元图和填充轮廓 - ggtern

转载 作者:行者123 更新时间:2023-12-01 19:38:58 26 4
gpt4 key购买 nike

我正在尝试使用库 ggtern 创建一个三元轮廓填充图。使用的代码是

a <- c(0.50, 0.625, 0.375, 0.25, 0.5625, 0.125, 0.25, 0.3125, 0.375, 0.4375, 0.1875, 0.3125, 0.375, 0.4375)
b <- c(0.25, 0.1875, 0.3125, 0.375, 0.25, 0.4375, 0.25, 0.375, 0.375, 0.4375, 0.875, 0.3125, 0.25, 0.125)
c <- c(0.25, 0.1875, 0.3125, 0.375, 0.1875, 0.4375, 0.50, 0.3125, 0.25, 0.125, 0.625, 0.375, 0.375, 0.4375)
d <- c(77.82325, 74.59318767, 76.76495015, 76.62122282, 77.95608657, 76.91320817, 68.50986659,8.53724416,80.32237597, 85.43315399, 61.80292426, 74.71471485, 73.27176908, 67.51782848)
df <- data.frame(a, b, c, d)

df$id <- 1:nrow(df)

#Build Plot
ggtern(data = df,aes(x = c,y = a,z = b)) +
stat_density2d(geom = "polygon", n = 400, aes(fill = ..level.., weight = d, alpha = abs(..level..))) +
geom_density_tern(aes(weight = d,color = ..level..), n = 400) +
geom_point(aes(fill = d),color = "black",size = 5,shape = 21) +
geom_text(aes(label = id),size = 3) +
labs(x = "X (%)",y = "Y (%)",z = "Z (%)",title = "Title", size = 3) +
scale_fill_gradient2(low = "green", mid = "yellow", high = "red", midpoint = 10) +
scale_color_gradient2(low = "green", mid = "yellow", high = "red", midpoint = 10) +
theme_custom(base_size = 12, base_family = "", col.T = "black", col.L = "black", col.R = "black", col.BG = "white") +
tern_anticlockwise() +
tern_limits(breaks = seq(0.1,1,by = 0.1)) + #AFFECT ALL SCALES
theme(axis.tern.arrowstart = 0.4,axis.tern.arrowfinish = 0.6) +
theme(legend.justification = c(0,1), legend.position = c(0,1)) +
guides(fill = guide_colorbar(order = 1), alpha = guide_legend(order = 2), color = "none") +
labs( title = "Ternary filled contour plot", fill = "Value, V",alpha = "|V - 0|")

但我收到以下警告消息:

Error: coord_tern requires the following missing aesthetics: z

为什么会出现这个错误,如何解决?请帮忙

最佳答案

@jhoward,感谢您对问题的解释。

我还想展示 ggtern 最新版本中的一些附加功能。请参阅下面的插值几何,用于曲面建模:

ggtern(data = df,aes(x = c,y = a, z = b)) + 
geom_interpolate_tern(aes(value=d,colour=..level..),bins=50) +
geom_point(aes(color=d),size=10) +
geom_text(aes(label=round(d,0)),size=3) +
theme_bw() +
theme(legend.position=c(0,1),
legend.justification=c(0,1)) +
scale_colour_gradient(low='green',high='red') +
labs( title = "Ternary filled contour plot", colour = "Value, V")

产生以下输出:

example contour

关于r - 三元图和填充轮廓 - ggtern,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32390466/

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