简体   繁体   English

数据点在我的R图上的位置错误

[英]Data points are in the wrong place on my R plot

I have two columns of data to plot into a scatter plot, the points don't appear to be in the correct place, as if the axis are shifted and the data points have been reordered. 我有两列数据要绘制成散点图,这些点似乎不在正确的位置,就好像轴已移动并且数据点已重新排序。 The data comes from a larger set and the plan was to use "lines" to add furthur lines to the plot. 数据来自较大的数据集,并且计划使用“线”在绘图中添加进一步的线。 I haven't been using R for long and am following the examples Line charts on the QuickR website. 我已经很长时间没有使用R了,并且正在遵循QuickR网站上的折线图示例。 The data has already been binned and should produce a distribution curve. 数据已经过分箱,应该会产生分布曲线。 The plan is to use the R code within knime, if/when it works. 如果可行,计划是在knime中使用R代码。

this is my data and code 这是我的数据和代码

1                  |   0.2  |                 ?
2                  |   0.3  |0.9040357526438414
3                  |   0.4  |5.411174917770767
4                  |   0.5  |6.680564306410919
5                  |   0.6  |6.209330779324634
6                  |   0.7  |6.064339545114229
7                  |   0.8  |6.689841006370736
8                  |   0.9  |8.755978393214562
9                  |   1.0  |13.11661304772278
10                 |   1.1  |17.093411510054928
11                 |   1.2  |15.479560872141883
12                 |   1.3  |8.420296969382726
13                 |   1.4  |3.5346457261075566
14                 |   1.5  |1.6256413200367157
15                 |   1.6  |2.2848049576096026
16                 |   1.7  |1.2394427974974978
17                 |   1.8  |0.28169014084507044
18                 |   1.9  |                 ?
19                 |   2.0  |                 ?
20                 |   2.1  |                 ?
21                 |   2.2  |                 ?
22                 |   2.3  |                 ?
23                 |   2.4  |                 ?
24                 |   2.5  |                 ?
25                 |   2.6  |                 ?
26                 |   2.7  |                 ?
27                 |   2.8  |                 ?
28                 |   2.9  |                 ?

nwells=c(2, 6, 10, 14, 18) #to take the columns I want from the larger dataset
plot(3, 20, type="n", xlim=c(0, 3), ylim=c(0, 26), xlab="Intensity",
    ylab="Proportion", xaxs="i", yaxs="i") 
colors <- rainbow(length(nwells)) 
linetype <- c(1:length(nwells)) 
plotchar <- seq(nwells)

# add lines 

      well <- data1[2]
  bin <-data1[1] 
  data<-data.frame(bin, well)
      lines(data, type="p", lwd=1.5,
        lty=1, col=colors[n], pch=plotchar[n], grid()) 

this is my plot distribution scatter plot 1 sample from R 这是我的地块分布散点图R中的样本1

note the point at 1.5, 5 - where does that come from in this data set? 注意1.5、5的点-该数据集中的位置是什么?

anybody any idea what I am doing wrong? 有人知道我在做什么错吗?

I think there is some issues due to incorrect conversion from factor to numeric variable in your data column 2, the following should fix it (not the point 1.5, 5 is not there anymore): 我认为由于数据列2中从系数数值变量的不正确转换而导致了一些问题,以下应予以解决(不再是1.5、5了):

data[,2] <- as.numeric(as.character(data[,2]))
well <- data1[2]
bin <-data1[1] 
data<-data.frame(bin, well)
lines(data, type="p", lwd=2.5,
      lty=1, col=colors, pch=plotchar, grid()) 

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM