本文介绍了如何在ggtern中使用geom_polygon正确填充颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! library(ggtern)$ b $这是我用来在三元图中创建边界的代码: (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()+ 主题(legend.position = c(0,1),legend.justification = c(0,1))+ 实验室(title =Sample Midpoint Segments) 此代码产生下图。 我想在每个部分填写不同的颜色。这个数字分为4个部分。您可以告诉我如何使用geom_polygon函数或任何其他函数在每个部分中填充不同的颜色吗?解决方案试试这个: g x = c(0 ,1,.4),z = c(0,0,.6),Series =Green) p x = c(0,0.210,0),z = c(0,0.315,.4),Series =Red) q x = c(0.040,0.210,0.4,0.1),z = c(0.385,0.315,0.6,0.9),Series =黄色) f 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) Here is the code which I am using to create boundaries in my ternary diagram: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")And this code produces the following diagram.I want to fill different colours in each section. This figure is divided into 4 sections. Could you kindly tell me how to fill different colours in each sections using geom_polygon function or any other function? 解决方案 Try this: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") 这篇关于如何在ggtern中使用geom_polygon正确填充颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-11 02:18