gpt4 book ai didi

r - 如何在ggtern中使用geom_polygon正确填充颜色?

转载 作者:行者123 更新时间:2023-12-01 01:50:35 25 4
gpt4 key购买 nike

这是我用来在三元图中创建边界的代码:

library(ggtern)
DATA <- data.frame(x = c(0,0,0.04),
y = c(1,0.6,0.575),
z = c(0,0.4,0.385),
xend = c(0.4,0.21,0.1),
yend = c(0.0,0.475,0),
zend = c(0.6,0.315,0.9),
Series = c("yz","xz","xy"))
ggtern(data=DATA,aes(x,y,z,xend=xend,yend=yend,zend=zend)) +
geom_segment(aes(color=Series),size=1) +
scale_color_manual(values=c("darkgreen","darkblue","darkred")) +
theme_bw() + theme_nogrid() +
theme(legend.position=c(0,1),legend.justification=c(0,1)) +
labs(title = "Sample Midpoint Segments")

这段代码产生了下图。

Click here to view the figure

我想在每个部分填充不同的颜色。此图分为 4 个部分。你能告诉我如何使用 geom_polygon 函数或任何其他函数在每个部分填充不同的颜色吗?

最佳答案

尝试这个:

g <- data.frame(y=c(1,0,0),
x=c(0,1,.4),
z=c(0,0,.6), Series="Green")

p <- data.frame(y=c(1,0.475,0.6),
x=c(0,0.210,0),
z=c(0,0.315,.4), Series="Red")

q <- data.frame(y=c(0.575,0.475,0.0,0.0),
x=c(0.040,0.210,0.4,0.1),
z=c(0.385,0.315,0.6,0.9), Series="Yellow")

f <- data.frame(y=c(0.6,0.575,0.0,0.0),
x=c(0.0,0.040,0.1,0.0),
z=c(0.4,0.385,0.9,1.0), Series="Blue")

DATA = rbind(g, p, q, f)
ggtern(data=DATA,aes(x,y,z)) +
geom_polygon(aes(fill=Series),alpha=.5,color="black",size=0.25) +
scale_fill_manual(values=as.character(unique(DATA$Series))) +
theme(legend.position=c(0,1),legend.justification=c(0,1)) +
labs(fill="Region",title="Sample Filled Regions")

enter image description here

关于r - 如何在ggtern中使用geom_polygon正确填充颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44795107/

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