plot - R plotting a dataset with NA Values -
this question has answer here:
- how connect dots there missing values? 3 answers
i'm trying plot dataset consisting of numbers , na entries in r.
v1,v2,v3 2, 4, 3 na, 5, 4 na,na,na na, 7, 3 6, 6, 9 should return same lines in plot, if had entered:
v1,v2,v3 2, 4, 3 3, 5, 4 4, 6, 3.5 5, 7, 3 6, 6, 9 what need r plotting dataset points, connect these points straight lines, - due size of dataset - more efficient actual calculation of each interpolated value within dataset. should not happen computing interpolations (via loop or that), instead on graph.
since dataset has multiple columns , using rs matplot function visualize it, there should way add multiple na-adjusted lines (as in matpot() or lines() example). hence plot(...) problematic because overwrites current graphics device.
mydf <- data.frame(v1=c(2,na,na,na,6),v2=c(4,5,na,7,6),v3=c(3,4,na,3,9)) plot(na,xlim=c(0,nrow(mydf)+1),ylim=c(min(mydf,na.rm=true)-1,max(mydf,na.rm=true)+1)) mapply(function(x,color){ dat <- na.omit(cbind(1:length(x),x)) lines(dat[,1],dat[,2],col=color) },mydf,c("red","blue","green")) 
Comments
Post a Comment