# Means Rotation in rENA

#### Cody L Marquart

#### 2020-10-11

    #library(rENA)

## Setting up

For this example, we will use the same accumulation as described in `vignette('getting-started',package="rENA")`, so review that document if anything in the following section is not clear.

## Create a Means Rotated Set

Creating and plotting a means rotated set is fairly similar to a standard set, however we will define the rotation function along with the groups of rotated points that will be rotated along their means. The rENA package comes with a function for means rotation, `ena.rotate.by.mean`, which is set as the `rotation.by` parameter of `ena.make.set`. Along with the function, `rotation.params` is set as the parameters we want to pass along to the rotation function. In the case of `ena.rotate.by.mean`, it expects `rotation.params` to be a `list` with two named elements, each containing a logical vector representing the rows of units to be included in particular group.

    ## Save references to the two vectors for easier re-use
    first.game = accum$meta.data$Condition == "FirstGame"
    second.game = accum$meta.data$Condition == "SecondGame"

    rotation.params = list(
      FirstGame = first.game,
      SecondGame = second.game
    )

    setMeansRotated = ena.make.set(
      enadata = accum,                   # The previously run accumulation above
      rotation.by = ena.rotate.by.mean,  # Function provided by rENA
      rotation.params = rotation.params  # The defined paremeters for rotation
    )

    first.points =  as.matrix(setMeansRotated$points$Condition$FirstGame)
    second.points = as.matrix(setMeansRotated$points$Condition$SecondGame)
    plot.rotated = ena.plot(setMeansRotated,  title = "Mean Rotation", scale.to = "p") %>%
                      ena.plot.points(points = first.points,  colors = c("red")) %>%
                      ena.plot.points(points = second.points, colors = c("blue")) %>%
                      ena.plot.group(point = first.points, colors =c("red"),
                                     confidence.interval = "box") %>%
                      ena.plot.group(point = second.points, colors =c("blue"),
                                     confidence.interval = "box")

    plot.rotated$plot