本文介绍了geom_ribbon中可能存在的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我希望能够绘制两个时间序列,并且根据当时的系列更大来遮蔽系列之间的空间。这里有两个系列 - 首先在一个数据框中带有一个指示符,指示当时哪个系列较大。 d1 d2 其中我绘制... ggplot()+ geom_line(data = d2, aes(x = time,y = value,group = variable,color = variable))+ geom_hline(yintercept = 0,linetype = 2)+ geom_ribbon(data = d1 [d1 $ big ==B,], aes(x =时间,ymin = csa, ymax = csb), alpha = .25 , fill =#9999CC)+ geom_ribbon(data = d1 [d1 $ big ==A,], aes(x = time,ymin = csb, ymax = csa), alpha = .25, fill =#CC6666)+ scale_color_manual(values = c(#CC6666,#9999CC)) 导致... 为什么会有一个多余的蓝色带在情节的中间? 解决方案这是一个解决方案。我用第一个 geom_ribbon 函数替换了 data = d1 [d1 $ big ==B,] / p> data = rbind(d1 [d1 $ big ==B,], d1 [c (diff(as.numeric(d1 $ big))== -1)+ 1),(which(diff(as.numeric(d1 $ big))== 1))),]) 自从第一行和最后一行 d1 $ big ==B 序列通常包含不同的 csa 和 csb 值。因此,有一个可见的功能区连接数据。上述命令使用之前的最后一行以及这些序列之后的第一行以及第一个功能区的数据。 d1 $ big ==A(第二个功能区的底部)不存在此问题。 完整的代码: ggplot()+ geom_line(data = d2, aes(x = time,y = value,group = variable,color = variable))+ geom_hline(yintercept = 0,linetype = 2)+ geom_ribbon(data = rbind(d1 [d1 $ (=(数字(d1 $大))== -1)+ 1),(其中(diff(as .numeric(d1 $ big))== 1))),]), aes(x = time,ymin = csa,ymax = csb), alpha = .25,fill =# 9999CC)+ geom_ribbon(data = d1 [d1 $ big ==A,], aes(x = time,ymin = csb,ymax = csa), alpha = .25,fill =#CC6666)+ scale_color_manual(values = c(#CC6666,#9999CC)) i was hoping to plot two time series and shade the space between the series according to which series is larger at that time.here are the two series-- first in a data frame with an indicator for whichever series is larger at that timed1 <- read.csv("https://dl.dropbox.com/s/0txm3f70msd3nm6/ribbon%20data.csv?dl=1")And this is the melted series.d2 <- read.csv("https://dl.dropbox.com/s/6ohwmtkhpsutpig/melted%20ribbon%20data.csv?dl=1")which I plot...ggplot() + geom_line(data = d2, aes(x = time, y = value, group = variable, color = variable)) + geom_hline(yintercept = 0, linetype = 2) + geom_ribbon(data = d1[d1$big == "B",], aes(x = time, ymin = csa, ymax = csb), alpha = .25, fill = "#9999CC") + geom_ribbon(data = d1[d1$big == "A",], aes(x = time, ymin = csb, ymax = csa), alpha = .25, fill = "#CC6666") + scale_color_manual(values = c("#CC6666" , "#9999CC"))which results in...why is there a superfluous blue band in the middle of the plot? 解决方案 Here is a solution. I replaced data = d1[d1$big == "B",] in the first geom_ribbon function with:data = rbind(d1[d1$big == "B",], d1[c((which(diff(as.numeric(d1$big)) == -1) + 1), (which(diff(as.numeric(d1$big)) == 1))), ])This is necessary since the first and last rows of d1$big == "B" sequences often contain different csa and csb values. As a result, there is a visible ribbon connecting the data. The above command uses the last rows before and the first rows after these sequences together with the data for the first ribbon.This problem does not exist for d1$big == "A" (the base for the second ribbon).The complete code:ggplot() + geom_line(data = d2, aes(x = time, y = value, group = variable, color = variable)) + geom_hline(yintercept = 0, linetype = 2) + geom_ribbon(data = rbind(d1[d1$big == "B",], d1[c((which(diff(as.numeric(d1$big)) == -1) + 1), (which(diff(as.numeric(d1$big)) == 1))), ]), aes(x = time, ymin = csa, ymax = csb), alpha = .25, fill = "#9999CC") + geom_ribbon(data = d1[d1$big == "A",], aes(x = time, ymin = csb, ymax = csa), alpha = .25, fill = "#CC6666") + scale_color_manual(values = c("#CC6666" , "#9999CC")) 这篇关于geom_ribbon中可能存在的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-05 20:19