黄土线的散点图,黄土不显示给定区域中的线 [英] scatter plot with loess line, loess to not show line in a given region

查看:162
本文介绍了黄土线的散点图,黄土不显示给定区域中的线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里绘制染色体的长度值

I plot here values over length for a chromosome

没有点的中间区域不包含任何数据,也不应该有一条黄土线. 如何修改我的代码以停止该区域的黄土行? 数据是连续的,但是我可以添加行以使用一些特殊值标记空白区域,或者添加带有标签的列?但是如何在命令中使用它呢?

The middle region without points contains no data and should not get a loess line. How can I modify my code to stop the loess line over this region? The data is continuous but I could add lines to mark the blank region with some special value or add a column with a label?? but how to use this in the command?

我当前的命令:

library(IDPmisc)

# plot settings (edit here)
spanv<-0.05
pointcol1="#E69F00"
pointcol2="#56B4E9"
pointcol3="#009E73"
points=20
linecol="green"
xlabs=paste(onechr, " position", " (loess-span=", spanv, ")", sep="")

data1<-NaRV.omit(data[,c(2,7)]) # keep only x and y for the relevant data 
                                # and clean NA and Inf
ylabs='E / A - ratio'
p1<-ggplot(data1, aes(x=start, y=E.R)) +
ylim(0,5) +
geom_point(shape=points, col=pointcol1, na.rm=T) +
geom_hline(aes(yintercept=1, col=linecol)) +
geom_smooth(method="loess", span=spanv, fullrange=F, se=T, na.rm=T) +
xlab(xlabs) +
ylab(ylabs)

推荐答案

我会做两件事之一:

  1. ggplot()之外进行loess()拟合,分别预测两个区域,并使用自己的geom_line()图层将每组预测添加到绘图中.
  2. 与上述类似,但是这次在ggplot()操作范围内.使用geom_smooth()将两层添加到绘图中,而不要添加两层,但重要的是更改提供给每层的data参数以仅引用数据的一部分或另一部分.
  1. Do the loess() fitting outside of ggplot(), predict for the two regions separately and add each set of predictions to the plot with its own geom_line() layer.
  2. Similar to the above, but this time within ggplot() realm of operations. Add two layers to the plot, not one, both using geom_smooth(), but importantly change the data argument supplied to each to refer to just one or the other portion of data.

对于后者,也许是这样的:

For the latter, perhaps something like:

....
geom_smooth(data = data[1:n, ], method="loess", span=spanv, fullrange=FALSE, 
            se=TRUE, na.rm=TRUE) +
geom_smooth(data = data[m:k, ], method="loess", span=spanv, fullrange=FALSE, 
            se=TRUE, na.rm=TRUE)
....

其中nmk指的是标记集1的结尾和集2的开始和结尾的索引,这些索引需要由您直接定义或提供.

where n and m and k refer to the indices that mark the end of set 1 and the start and end of set 2 and which need to be defined or supplied by you directly.

这篇关于黄土线的散点图,黄土不显示给定区域中的线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆