Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

quantile points on mt_plot

Hello,

I am currently drawing some trajectory plots with mt_plot_aggregate like this:

Traj <- mt_plot_aggregate(data = mt_data, use="tn_trajectories", color="condition", subject_id="subjID", size=1.0)  + scale_color_manual(values=c("#00BFC4", "#F8766D", "grey"), labels = c("Phonological", "Semantic", "Unrelated")) + xlim(-1000, 300) + ylim(-100, 1100) +  geom_point()

However, I don't want to have all the 'points' on my trajectory but only 10th, 20th,...100th points. I wonder if you know how to do this with MT data?


Wenting

Comments

  • Hi Wenting,

    I don't know Mousetrap, but if mt_data is just a data frame, you can make a copy of that data frame where you remove all rows except the ones that you keep. If you want to keep every tenth trial, this procedure could work:

    1) Copy mt_data

    2) Get the indices from the mt_data, run the modulo operator on it, and compare which values are equal to 0. This will give you a list with indices corresponding to the rows you want to keep

    3) Select only those rows whose index is in the list that you generated in (2).

    Does that make sense?

    Eduard

    ps. maybe mt_plot_aggregate has a filter function for that purpose, in case you can probably open the documentation of it (?mt_plot_aggregate).

    Buy Me A Coffee

  • Hi Wenting,

    thanks, @eduard, for comment. The documentation of mt_plot_aggregate and examples can also be found online at: http://pascalkieslich.github.io/mousetrap/reference/mt_plot.html

    Eduard's general approach would work.

    In terms if mousetrap: One approach would be to specify that you only want 11 points per trajectory in mt_time_normalize and then print them. Using the standard data in mousetrap as an example:

    library(mousetrap)
    
    # Time-normalize trajectories (only 11 points)
    KH2017 <- mt_time_normalize(KH2017, nsteps = 11)
    
    # Plot aggregated time-normalized trajectories per condition with points
    mt_plot_aggregate(
     KH2017, use="tn_trajectories",
     color="Condition",
     points = TRUE
    )
    

    @Wenting: However, this means that the line is also only based on the 11 points per trajectory - not sure if this is what you desired.

    If you want to plot the trajectory lines based on the standard 101 points per trajectory but only include points for every tenth position, you could use mt_aggregate (http://pascalkieslich.github.io/mousetrap/reference/mt_aggregate.html) to create a dataset that contains the aggreate time-normalized trajectories. These you can plot using ggplot2 (and then you only plot a subset of points). For the standard example above it could work like this:

    library(mousetrap)
    library(ggplot2)
    
    # Time-normalize trajectories
    KH2017 <- mt_time_normalize(KH2017)
    
    # Aggregate time-normalized trajectories per condition
    average_trajectories <-  mt_aggregate(
      KH2017, use="tn_trajectories",
      use2_variables="Condition"
    )
    
    # Plot trajectories
    ggplot(average_trajectories, aes(x = xpos, y = ypos, color = Condition, group = Condition)) +
      geom_path() +
      geom_point(data = subset(average_trajectories, steps %in% seq(1, 101, 10)))
    

    Hope this helps.

    Best,

    Pascal

  • Thank you both for the prompt reply!

    I tried Pascal's second suggestion and it works really well. Thank you so much!


    Wenting

Sign In or Register to comment.