# Turning a set of random walk data 45 degrees

I have a set of data that is just a "random" (generated by me, not by computer) sequence of length 2000 of 1's and (-1)'s. I used it to plot a 1-D random walk where +1 is step up, (-1) is step down, so my graph looked like this: I was asked to break the sequence in half and plot the first half against the second to create a 2-D random walk graph. This was easy enough, I just did it in excel. But I was then asked to turn the graph 45 degrees CCW so it looks like it's laid over a grid. So i guess if the first point is (1,1) it would go to (0,1), if it's (-1,1) it would go to (-1,0) and so on. I'm not sure how to do that. Please let me know if you know of a way to do it in Excel or Mathematica.

ListLinePlot[Accumulate @ Prepend[RandomChoice[{{-1, 0}, {1, 0}, {0, -1}, {0, 1}}, 1000],
{1, 1}], AspectRatio -> Automatic] Starting with some random data

rd = RandomChoice[{1, -1}, 2000];

ListLinePlot[Accumulate@rd] Creating a random walk similar to the one shown in your question

rw = Accumulate@Transpose[{rd[[;; 1000]], rd[[1001 ;;]]}];

ListLinePlot[rw, AspectRatio -> Automatic] and rotating it by 45°

rwr = rw.(RotationMatrix[45 Degree]/Sqrt);

ListLinePlot[rwr, AspectRatio -> Automatic] • Oo! Very nice :] But I need to do that with the data that I already have. The whole point is that it's not randomly generated by a computer, but randomly generated by a person. Mar 27 '15 at 0:37
• @Solarmew In my edit I show a way how to start with random data similar to yours, create the 2D random walk the same way you did, and than rotate it by 45 degrees. Mar 27 '15 at 1:10
• @Solarmew Do you want the rotated data to be on a 1 x 1 grid as shown in the last plot of my answer or on a Sqrt x Sqrt grid as shown in the other answers? Mar 27 '15 at 1:22
• Rotation is clockwise instead of CCW. see my solution in this thread for correct answer Mar 27 '15 at 1:37
• @penguin77 Rotation is 45 degrees. For a -45 degrees rotation just replace RotationMatrix[45 Degree] with RotationMatrix[-45 Degree]. Mar 27 '15 at 8:48
rw = Accumulate@RandomChoice[{-1, 1}, 400];
ListLinePlot[rw, AspectRatio -> 1] rw2 = Transpose[{rw[[ ;; 200]], rw[[201 ;; ]]}];

llp2 = ListLinePlot[rw2, AspectRatio -> 1] To rotate llp2:

Show[MapAt[GeometricTransformation[#, RotationTransform[-45 Degree]] &,
llp2, {1}], PlotRange -> All] Aside: Using InterpolationOrder->0 gives "axes-aligned" lines (but it does not actually correspond to rw2)

ListLinePlot[rw2, AspectRatio -> 1, InterpolationOrder -> 0] No need folding 1D graph to get a 2D Random walk in Mathematica. and the CCW easy in Mathematica. Here we go:

Generate data set for the random sequence with 2000 steps. Alternatively, you may use your "own generated" data set.

rdata = Accumulate[RandomChoice[{-1, 1}, {2000, 2}]]


Now plot it with similar layout as your example

ListLinePlot[rdata, GridLines -> {{0}, Range[-40, 30, 10]}]


Here the result (Nicer than Excel...much nicer,hi,hi,hi) Now you wish to turn it CCW, for whatever reason? Ok no problem Create a Transformation Function

r = RotationTransform[45 Degree, {{1, 0}, {0, 1}}]


Apply this function....

 ListLinePlot[r @ rdata , GridLines -> {{0}, Range[-40, 30, 10]}] What you mean with Excel??? never heard about it...hi,hi,hi