本文介绍了geom_line - 同一行中的不同颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 你好我有一个关于geom_line的问题。 我想要做的是,对于同一行,根据某些过滤器的不同颜色段适用于另一个变量即不是用于绘制线条的变量。例如,如果我们有一个带有标题时间的数据框,var1和var2 $ b b time var1 var2 如果我有绘图时间与var1使用geom_line,可以说我想通过在变量var2上应用超过10的过滤器来对线条着色。所以这条线在时间1,2,6,7上将具有相同的颜色,并且在3,4,5中具有另一种颜色。 请告诉我这是否可能?如果是这样,请给我一些指示。解决方案这就是你想要的吗? time var1 var2 DF ggplot(DF,aes(time,var1,color =(var2> 10)))+ geom_line(aes(group = 1)) hi I have a question on geom_line.what i want to do is, for the same line, have different colour segments according to some filter apply to another variable i.e not the variable used to plot the line.for example if we have a dataframe with header time, var1 and var2time <- seq (1,7,1)var1 <- c(3,5,7,2,3,2,8)var2 <- c(2,4,18,16,12,3,2)if i have plot time vs var1 using geom_line and lets say i want to colour the line by applying a filter of above 10 on variable var2. so the line will have the same colour for time 1,2,6,7 and another colour for 3,4,5. please tell me if this is possible? if so, please give me some directions. 解决方案 Is this what you want?time <- seq (1,7,1)var1 <- c(3,5,7,2,3,2,8)var2 <- c(2,4,18,16,12,3,2)DF <- data.frame(time, var1, var2)ggplot(DF, aes(time, var1, colour=(var2>10))) + geom_line(aes(group=1)) 这篇关于geom_line - 同一行中的不同颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-21 20:47