我有3列数据。在列数据范围从大约0,0727 到10,2989。
这就是它的样子:
http://i61.tinypic.com/2uen3hz.jpg
我的代码
MyData <- read.csv2(file="C:/Users/Sysop/Desktop/Koncentracija.csv",header=T,sep=";")
MyData
Data_1<-MyData$Sul311
Data_2<-MyData$Sul322
Data_3<-MyData$Sul333
Data_1_density<- density(Data_1,na.rm = TRUE)
Data_2_density<- density(Data_2,na.rm = TRUE)
Data_3_density<- density(Data_3,na.rm = TRUE)
xlim <- range(Data_1_density$x,Data_2_density$x,Data_3_density$x, na.rm = TRUE)
ylim <- range(Data_1_density$y, Data_2_density$y, Data_3_density$y, na.rm = TRUE)
Col_1 <- rgb(1,0,0,0.4)
Col_2 <- rgb(0,0,1,0.4)
Col_3 <- rgb(0,1,0,0.4)
plot(Data_1_density, xlim = xlim, ylim = ylim, xlab = 'Zn concentracion, mg/l',main = 'Distribution of data', panel.first = grid(nx = 10, ny = 10))
polygon(Data_1_density, density = -1, col = Col_1)
polygon(Data_2_density, density = -1, col = Col_2)
polygon(Data_3_density, density = -1, col = Col_3)
legend('topright',c('distribution 1 ','distribution 2','distribution 3'),cex=1.0, fill = c(Col_1, Col_2, Col_3), bty = 'n',border = NA)
但是我们可以看到密度图从负值开始,但我的数据没有任何负值。一列缺少一个值,因此R显示为NA,但我使用(na.rm = TRUE)忽略NA值。 那么这些密度图是否正确绘制?
这是我的数据:
Sul311 Sul322 Sul333
1,8032 NA 2,3981
3,4949 3,1696 1,8218
0,5856 0,5577 0,0837
0,1859 1,5894 0,093
1,4686 1,45 2,9744
0,079 0,0727 0,0543
1,0317 1,0782 2,7513
0,5112 0,5484 0,9295
1,3943 1,1805 2,7513
1,1526 1,1619 2,6305
1,3013 10,2989 5,577
0,5949 0,5856 0,725
0,1766 0,2696 1,6917
0,4229 0,3309 1,1089
1,1953 0,3328 1,6787
1,4853 0,6116 1,8367
0,4443 0,3514 1,2939
0,5912 0,3309 1,2901
答案 0 :(得分:1)
您可以定义开头或&#34;第一个值&#34;使用from参数:
density(x, na.rm=T, from=min(x, na.rm=T))
例如