【发布时间】:2020-02-19 23:56:34
【问题描述】:
我正在寻找改变新列以使用 dplyr 分配顶部和底部 20% 的值的方法。
这是我的代码,但对我来说效果不佳。
DF1 <- DF %>%
group_by(Timepoint) %>%
filter (!is.na (log2_Concentration)) %>%
arrange (desc(log2_Concentration)) %>%
mutate (top_bottom=ifelse (log2_Concentration=top_frac(.2), "TOP20PERC",
ifelse (log2_Concentration=top_frac(-.2), "BOTTOM20PERC", "MID")))
ggplot(DF1, aes(x = Timepoint, y=log2_Concentration,fill=Timepoint)) +
geom_boxplot() +
geom_jitter(size=1,position=position_jitter(0.2), aes(col=DF1$top_bottom)) +
scale_colour_manual(values = c("red", "gray", "blue"),
labels = c("TOP20PERC", "MID", "BOTTOM20PERC"))
我希望为每个时间点分配前 20%、后 20% 和其余的作为 MID,以便我可以在我的 ggplot 中为这些点着色。
[
非常感谢大师!
【问题讨论】:
-
您似乎已将问题主题从数据处理更改为绘图。尚不清楚您是否从数据中获得了上面的图并且不喜欢它的某些方面(或者?)您正在尝试模仿它。无论哪种情况,这都是一个新问题,您应该接受下面对您之前的问题的回答并发布一个新问题,但这次您应该提供minimal reproducible example。
标签: r if-statement dplyr