0

I have a dataset containing two time-points (T1, T2), two groups (Group A, Group B), and three types of emotional faces (happy, sad, neutral) and reaction time as the dependent variable. I have used a bar plot to represent the data using R. Are there any other graphs that can be used to represent this kind of data? A sample dataset is given below (for each participant, there are three emotion types and two time-points):

participant emotion group time rt
AA happy groupA t1 47.09
AA happy groupA t2 40.09
AA sad groupA t1 33.99
AA sad groupA t2 33.99
AA neutral groupA t1 104.97
AA neutral groupA t2 98.75
AB happy groupB t1 54.65
AB happy groupB t2 64.65
AB sad groupB t1 53.99
AB sad groupB t2 43.99
AB neutral groupB t1 24.97
AB neutral groupB t2 98.75
Christina
  • 9
  • 7

2 Answers2

1

An option could be representing your data using geom_point like this:

library(ggplot2)
library(dplyr)
df %>%
  ggplot(aes(x = time, y = rt, color = emotion)) +
  geom_point(alpha = 0.4, size = 2) +
  facet_wrap(~participant)

Created on 2022-07-30 by the reprex package (v2.0.1)

Another option if you only want to represent your categorical data, you could use a mosaic plot like this:

library(vcd)
mosaic(~ participant + emotion + time, data = df)

enter image description here

Please note: this works good if you have different proportion between categorical variables.

Quinten
  • 35,235
  • 5
  • 20
  • 53
  • Thank you for the suggestions. Is it possible to plot a mosaic plot using the data mentioned here. I have around 30 participants in each group. If so, how do you add the fourth variable? – Christina Aug 02 '22 at 04:08
  • @Christina, yes you can just simply add the fourth variable in the function like ohters! – Quinten Aug 02 '22 at 07:25
0

You want to plot the information of four different variables.

One way could be to use a 3D plot (e.g., using points instead of bars) and add the fourth dimension by coloring the data points. For instance: y-axis = rt, x-axis = time, z-axis = emotion, color = group.

library(plotly)

df <- data.frame(
  group = c(rep("A", 6), rep ("B", 6)),
  emotion = rep(c("happy", "happy", "sad", "sad", "neutral", "neutral"), 2),
  time = rep(c("t1", "t2"), 6),
  rt = c(47.09, 40.09, 33.99, 33.99, 104.97, 98.75, 54.65, 64.65, 53.99, 43.99, 24.97, 98.75)
)

plot_ly(df, x = ~time, y = ~rt, z = ~emotion, color = ~group)

enter image description here

Depending on the data (and your personal preferences), the plot could appear "overcrowded"/ not too easy to read. If this is the case (in my view, here it is), you can reduce one dimension from the suggestion above (e.g., make it a 2D plot) and create two plots (e.g., three 2D plots; left plot entitled "positive", middle plot entitled "negative", right plot entitled "neutral")

library(ggplot)

df <- data.frame(
  group = c(rep("A", 6), rep ("B", 6)),
  emotion = rep(c("happy", "happy", "sad", "sad", "neutral", "neutral"), 2),
  time = rep(c("t1", "t2"), 6),
  rt = c(47.09, 40.09, 33.99, 33.99, 104.97, 98.75, 54.65, 64.65, 53.99, 43.99, 24.97, 98.75)
)

df %>% 
  ggplot(aes(x = time, y = rt, group = group, color = group)) +
  geom_point(size = 3) +
  geom_line() +
  facet_wrap(~emotion)

enter image description here

Carlos Luis Rivera
  • 3,108
  • 18
  • 45
Daniela
  • 1
  • 1