[R] Plot unusual subset of data

(Ted Harding) ted.harding at wlandres.net
Mon Oct 24 22:32:39 CEST 2011


On 24-Oct-11 19:48:16, Noah Silverman wrote:
> Hi,
> I have a function that approximates some data and indicates "segments".
> 
> I'd like to plot the original data, and then the linear approximations
> on top of it.  (Ideally, just a subset of N rows at a time, as the data
> set is large.)
> 
> I can't figure out a clean way to do this.  Suggestions?
> 
> here is some sample data:
> 
> ==================================
> Row    X          Seg
> 
.
> 1013 1.4644 0.000000000
> 1014 1.4645 0.000000000
> 1015 1.4646 0.000000000
> 1016 1.4643 0.000000000
> 1017 1.4645 1
> 1018 1.4660 0.000000000
> 1019 1.4660 0.000000000
> 1020 1.4671 0.000000000
> 1021 1.4673 0.000000000
> 1022 1.4669 0.000000000
> 1023 1.4669 0.000000000
> 1024 1.4735 0.000000000
> 1025 1.4744 1
> 1026 1.4752 0.000000000
> 1027 1.4741 0.000000000
> 1028 1.4763 0.000000000
> 1029 1.4770 0.000000000
> 1030 1.4770 0.000000000
> 1031 1.4762 0.000000000
> 1032 1.4762 0.000000000
> 1033 1.4771 0.000000000
> 1034 1.4771 0.000000000
> 1035 1.4771 0.000000000
> 1036 1.4752 0.000000000
> 1037 1.4763 0.000000000
> 1038 1.4763 0.000000000
> 1039 1.4761 0.000000000
> 1040 1.4771 0.000000000
> 1041 1.4758 0.000000000
> 1042 1.4747 0.000000000
> 1043 1.4756 0.000000000
> 1044 1.4753 0.000000000
> 1045 1.4749 1
> 1046 1.4768 0.000000000
> 
.
> ===============================
> 
> So, in this example, I want:
> 1) linear plot of X:    plot( X[1013:1046],  type="l")
> 2) Lines from 1017,1.4645 to 1025,1.4744  etc..  I tried  lines(
> X[Seg>0], col=2)  But this fails.
> 
> Any suggestions?
> --
> Noah Silverman

I would suggest something on the lines of:

  ix <- which(Seg[1013:1046] > 0)
  lines((1013:1046)[ix], Seg[1013:1046][ix], col=2)

Hoping this helps,
Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <ted.harding at wlandres.net>
Fax-to-email: +44 (0)870 094 0861
Date: 24-Oct-11                                       Time: 21:32:28
------------------------------ XFMail ------------------------------



More information about the R-help mailing list