---
title: "lit-review"
output: html_document
date: "2026-09-04"
---

```{r}
library(dplyr)
library(plotly)
library(readxl)

```

```{r}
data <- read_excel("Cube bibliography (1-104).xlsx")

```



```{r}
cube_data <- data %>% 
  select(7:11) %>% 
  rename(
    "Author" = 1,
    "Year" = 2,
    "Modality" = 3,
    "Discourse Type" = 4,
    "Engagement" = 5
  ) %>% 
  mutate(
    modality_num = case_when(
      Modality == "speech only" ~ 0,
      Modality == "speech + visual (static: pictures/drawings)" ~ 0.5,
      Modality == "speech + visual (dynamic: videos)" ~ 1,
      .default = 0.5
    ),
    
    discourse_num = case_when(
      `Discourse Type` == "monologue" ~ 0,
      `Discourse Type` == "dialogue" ~ 1,
      `Discourse Type` == "in between (closer to dialogue)" ~ 0.75,
      `Discourse Type` == "in between (closer to monologue)" ~ 0.25,
      .default = 0.5
    ),
    
    engagement_num = case_when(
      Engagement == "passive (pressing buttons, comprehension task after the stimuli)" ~ 0,
      Engagement == "active (production task, interaction with someone else, etc.)" ~ 1,
      Engagement == "in between (closer to active)" ~ 0.75,
      Engagement == "in between (closer to passive)" ~ 0.25,
      .default = 0.5
    )
  ) %>%
  count(
    modality_num,
    engagement_num,
    discourse_num
  ) %>%
  mutate(
    proportion = n / sum(n),
    percentage = proportion * 100,
    
    # Show labels only for >3%
    label = if_else(
      proportion > 0.05,
      paste0(round(percentage, 1), "%"),
      ""
    )
  )
```

Statistics

```{r}

# n of annotated studies
nrow(data)
sum(cube_data$n)


table_summary <- cube_data %>% 
  rename(Modality = modality_num,
         Engagement = engagement_num,
         DiscourseType = discourse_num, 
         N = n) %>% 
  mutate(Proportion = round(proportion*100,2)) %>% 
  select(1:4,8)

write.csv(table_summary, "table.csv")
```



```{r}
# ---------------------------------------------------------
# 8 vertices of the cube
# ---------------------------------------------------------

cube_vertices <- expand.grid(
  x = c(0, 1),
  y = c(0, 1),
  z = c(0, 1)
)


# ---------------------------------------------------------
# 12 edges of the cube
# ---------------------------------------------------------

cube_edges <- list(
  c(1, 2),
  c(1, 3),
  c(1, 5),
  c(2, 4),
  c(2, 6),
  c(3, 4),
  c(3, 7),
  c(5, 6),
  c(5, 7),
  c(4, 8),
  c(6, 8),
  c(7, 8)
)
```


```{r}
# ---------------------------------------------------------
# Start plot
# ---------------------------------------------------------

p <- plot_ly()


# ---------------------------------------------------------
# Add cube edges
# ---------------------------------------------------------

for (edge in cube_edges) {
  
  p <- p %>%
    add_trace(
      data = cube_vertices[edge, ],
      x = ~x,
      y = ~y,
      z = ~z,
      
      type = "scatter3d",
      mode = "lines",
      
      line = list(
        color = "grey",
        width = 2
      ),
      
      hoverinfo = "none",
      showlegend = FALSE
    )
}


# ---------------------------------------------------------
# Add 8 cube vertices
# ---------------------------------------------------------

p <- p %>%
  add_trace(
    data = cube_vertices,
    x = ~x,
    y = ~y,
    z = ~z,
    
    type = "scatter3d",
    mode = "markers",
    
    marker = list(
      size = 1,
      color = "black",
      opacity = 0.8
    ),
    
    hoverinfo = "none",
    showlegend = FALSE
  )


# ---------------------------------------------------------
# Add study bubbles
# ---------------------------------------------------------

p <- p %>%
  add_trace(
    data = cube_data,
    
    z = ~modality_num,
    y = ~discourse_num,
    x = ~engagement_num,
    
    # Bubble size = proportion
    size = ~proportion,
    
    # Labels only for >3%
    text = ~label,
    textposition = "right center",
    
    textfont = list(
      size = 14,
      family = "Helvetica",
      colour = 'red'
      
    ),
    
    # Hover information
    hovertext = ~paste0(
      "Studies: ", n,
      "<br>Proportion: ", round(percentage, 1), "%"
    ),
    hoverinfo = "text",
    
    type = "scatter3d",
    mode = "markers+text",
    
    marker = list(
      symbol = "circle",
      sizemode = "diameter",
      opacity = 0.4,
      
      # Colour = proportion
      color = "red",
      
      cmin = 0,
      cmax = max(cube_data$proportion),
      
      line = list(
        color = "red",
        width = 1
      )
    )
  )


# ---------------------------------------------------------
# Layout
# ---------------------------------------------------------

p <- p %>%
  layout(
    
    font = list(
      family = "Helvetica"
    ),
    
    scene = list(
  xaxis = list(
    title = list(
      text = "Engagement<br>(Passive - Active)",
      font = list(family = "Helvetica", size = 18, color = "white")
    ),
    showticklabels = FALSE,
    ticks = "",
    showgrid = FALSE,
    showline = FALSE,
    zeroline = FALSE,
    range = c(0, 1)
  ),

  yaxis = list(
    title = list(
      text = "Discourse Type<br>(Monologue - Dialogue)",
      font = list(family = "Helvetica", size = 18, color = "white")
    ),
    showticklabels = FALSE,
    ticks = "",
    showgrid = FALSE,
    showline = FALSE,
    zeroline = FALSE,
    range = c(0, 1)
  ),

  zaxis = list(
    title = list(
      text = "Modality<br>(Unimodal - Multimodal)",
      font = list(family = "Helvetica", size = 18, color = "white")
    ),
    showticklabels = FALSE,
    ticks = "",
    showgrid = FALSE,
    showline = FALSE,
    zeroline = FALSE,
    range = c(0, 1)
  )
))
 


# ---------------------------------------------------------
# Display
# ---------------------------------------------------------

# X
p <- p %>%
  add_trace(
    x = 0,
    y = 0,
    z = 0,
    type = "scatter3d",
    mode = "text",
    text = "X",
    textposition = "top right",
    textfont = list(
      size = 22,
      family = "Helvetica"
    ),
    hoverinfo = "none",
    showlegend = FALSE
  )

# A
p <- p %>%
  add_trace(
    x = 1,
    y = 1,
    z = 1,
    type = "scatter3d",
    mode = "text",
    text = "A",
    textposition = "top right",
    textfont = list(
      size = 22,
      family = "Helvetica"
    ),
    hoverinfo = "none",
    showlegend = FALSE
  )

# g

p <- p %>%
  add_trace(
    x = 0,
    y = 0,
    z = 1,
    type = "scatter3d",
    mode = "text",
    text = "g",
    textposition = "top right",
    textfont = list(
      size = 22,
      family = "Helvetica"
    ),
    hoverinfo = "none",
    showlegend = FALSE
  )


# b

p <- p %>%
  add_trace(
    x = 0,
    y = 1,
    z = 1,
    type = "scatter3d",
    mode = "text",
    text = "b",
    textposition = "top right",
    textfont = list(
      size = 22,
      family = "Helvetica"
    ),
    hoverinfo = "none",
    showlegend = FALSE
  )


# e

p <- p %>%
  add_trace(
    x = 1,
    y = 0,
    z = 0,
    type = "scatter3d",
    mode = "text",
    text = "e",
    textposition = "bottom left",
    textfont = list(
      size = 22,
      family = "Helvetica"
    ),
    hoverinfo = "none",
    showlegend = FALSE
  )


# f

p <- p %>%
  add_trace(
    x = 1,
    y = 0,
    z = 1,
    type = "scatter3d",
    mode = "text",
    text = "f",
    textposition = "top left",
    textfont = list(
      size = 22,
      family = "Helvetica"
    ),
    hoverinfo = "none",
    showlegend = FALSE
  )


# d

p <- p %>%
  add_trace(
    x = 1,
    y = 1,
    z = 0,
    type = "scatter3d",
    mode = "text",
    text = "d",
    textposition = "bottom right",
    textfont = list(
      size = 22,
      family = "Helvetica"
    ),
    hoverinfo = "none",
    showlegend = FALSE
  )

# c

p <- p %>%
  add_trace(
    x = 0,
    y = 1,
    z = 0,
    type = "scatter3d",
    mode = "text",
    text = "c",
    textposition = "bottom right",
    textfont = list(
      size = 22,
      family = "Helvetica"
    ),
    hoverinfo = "none",
    showlegend = FALSE
  )


```

```{r}
p
```

```{r}
htmlwidgets::saveWidget(
  p,
  file = "bias_in_literature_3D.html",
  selfcontained = TRUE
)
```
# Base only

```{r}
# ---------------------------------------------------------
# Start plot
# ---------------------------------------------------------

p1 <- plot_ly()


# ---------------------------------------------------------
# Add cube edges
# ---------------------------------------------------------

for (edge in cube_edges) {
  
  p1 <- p1 %>%
    add_trace(
      data = cube_vertices[edge, ],
      x = ~x,
      y = ~y,
      z = ~z,
      
      type = "scatter3d",
      mode = "lines",
      
      line = list(
        color = "grey",
        width = 2
      ),
      
      hoverinfo = "none",
      showlegend = FALSE
    )
}


# ---------------------------------------------------------
# Add 8 cube vertices
# ---------------------------------------------------------

p1 <- p1 %>%
  add_trace(
    data = cube_vertices,
    x = ~x,
    y = ~y,
    z = ~z,
    
    type = "scatter3d",
    mode = "markers",
    
    marker = list(
      size = 1,
      color = "black",
      opacity = 0.8
    ),
    
    hoverinfo = "none",
    showlegend = FALSE
  )



# ---------------------------------------------------------
# Layout
# ---------------------------------------------------------

p1 <- p1 %>%
  layout(
    
    font = list(
      family = "Helvetica"
    ),
    
    scene = list(
  xaxis = list(
    title = list(
      text = "Engagement<br>(Passive - Active)",
      font = list(family = "Helvetica", size = 18)
    ),
    showticklabels = FALSE,
    ticks = "",
    showgrid = FALSE,
    showline = FALSE,
    zeroline = FALSE,
    range = c(0, 1)
  ),

  yaxis = list(
    title = list(
      text = "Discourse Type<br>(Monologue - Dialogue)",
      font = list(family = "Helvetica", size = 18)
    ),
    showticklabels = FALSE,
    ticks = "",
    showgrid = FALSE,
    showline = FALSE,
    zeroline = FALSE,
    range = c(0, 1)
  ),

  zaxis = list(
    title = list(
      text = "Modality<br>(Unimodal - Multimodal)",
      font = list(family = "Helvetica", size = 18)
    ),
    showticklabels = FALSE,
    ticks = "",
    showgrid = FALSE,
    showline = FALSE,
    zeroline = FALSE,
    range = c(0, 1)
  )
))
 


# ---------------------------------------------------------
# Display
# ---------------------------------------------------------

# ---------------------------------------------------------
# Add coloured circles + black bold letters
# ---------------------------------------------------------

# X
p1 <- p1 %>%
  add_trace(
    x = 0, y = 0, z = 0,
    type = "scatter3d",
    mode = "markers",
    marker = list(
      size = 16,
      color = "grey",
      opacity = 0.9
    ),
    hoverinfo = "none",
    showlegend = FALSE
  ) %>%
  add_trace(
    x = 0, y = 0, z = 0,
    type = "scatter3d",
    mode = "text",
    text = "X",
    textposition = "middle center",
    textfont = list(
      size = 16,
      family = "Helvetica",
      color = "black"
    ),
    hoverinfo = "none",
    showlegend = FALSE
  )


# A
p1 <- p1 %>%
  add_trace(
    x = 1, y = 1, z = 1,
    type = "scatter3d",
    mode = "markers",
    marker = list(
      size = 16,
      color = "deeppink3",
      opacity = 0.9
    ),
    hoverinfo = "none",
    showlegend = FALSE
  ) %>%
  add_trace(
    x = 1, y = 1, z = 1,
    type = "scatter3d",
    mode = "text",
    text = "A",
    textposition = "middle center",
    textfont = list(
      size = 16,
      family = "Helvetica",
      color = "black"
    ),
    hoverinfo = "none",
    showlegend = FALSE
  )


# g
p1 <- p1 %>%
  add_trace(
    x = 0, y = 0, z = 1,
    type = "scatter3d",
    mode = "markers",
    marker = list(
      size = 16,
      color = "green",
      opacity = 0.9
    ),
    hoverinfo = "none",
    showlegend = FALSE
  ) %>%
  add_trace(
    x = 0, y = 0, z = 1,
    type = "scatter3d",
    mode = "text",
    text = "g",
    textposition = "middle center",
    textfont = list(
      size = 16,
      family = "Helvetica",
      color = "black"
    ),
    hoverinfo = "none",
    showlegend = FALSE
  )


# b
p1 <- p1 %>%
  add_trace(
    x = 0, y = 1, z = 1,
    type = "scatter3d",
    mode = "markers",
    marker = list(
      size = 16,
      color = "aquamarine",
      opacity = 0.9
    ),
    hoverinfo = "none",
    showlegend = FALSE
  ) %>%
  add_trace(
    x = 0, y = 1, z = 1,
    type = "scatter3d",
    mode = "text",
    text = "b",
    textposition = "middle center",
    textfont = list(
      size = 16,
      family = "Helvetica",
      color = "black"
    ),
    hoverinfo = "none",
    showlegend = FALSE
  )


# e
p1 <- p1 %>%
  add_trace(
    x = 1, y = 0, z = 0,
    type = "scatter3d",
    mode = "markers",
    marker = list(
      size = 16,
      color = "orange",
      opacity = 0.9
    ),
    hoverinfo = "none",
    showlegend = FALSE
  ) %>%
  add_trace(
    x = 1, y = 0, z = 0,
    type = "scatter3d",
    mode = "text",
    text = "e",
    textposition = "middle center",
    textfont = list(
      size = 16,
      family = "Helvetica",
      color = "black"
    ),
    hoverinfo = "none",
    showlegend = FALSE
  )


# f
p1 <- p1 %>%
  add_trace(
    x = 1, y = 0, z = 1,
    type = "scatter3d",
    mode = "markers",
    marker = list(
      size = 16,
      color = "magenta",
      opacity = 0.9
    ),
    hoverinfo = "none",
    showlegend = FALSE
  ) %>%
  add_trace(
    x = 1, y = 0, z = 1,
    type = "scatter3d",
    mode = "text",
    text = "f",
    textposition = "middle center",
    textfont = list(
      size = 16,
      family = "Helvetica",
      color = "black"
    ),
    hoverinfo = "none",
    showlegend = FALSE
  )


# d
p1 <- p1 %>%
  add_trace(
    x = 1, y = 1, z = 0,
    type = "scatter3d",
    mode = "markers",
    marker = list(
      size = 16,
      color = "red",
      opacity = 0.9
    ),
    hoverinfo = "none",
    showlegend = FALSE
  ) %>%
  add_trace(
    x = 1, y = 1, z = 0,
    type = "scatter3d",
    mode = "text",
    text = "d",
    textposition = "middle center",
    textfont = list(
      size = 16,
      family = "Helvetica",
      color = "black"
    ),
    hoverinfo = "none",
    showlegend = FALSE
  )


# c
p1 <- p1 %>%
  add_trace(
    x = 0, y = 1, z = 0,
    type = "scatter3d",
    mode = "markers",
    marker = list(
      size = 16,
      color = "limegreen",
      opacity = 0.9
    ),
    hoverinfo = "none",
    showlegend = FALSE
  ) %>%
  add_trace(
    x = 0, y = 1, z = 0,
    type = "scatter3d",
    mode = "text",
    text = "c",
    textposition = "middle center",
    textfont = list(
      size = 16,
      family = "Helvetica",
      color = "black"
    ),
    hoverinfo = "none",
    showlegend = FALSE
  )


# h
p1 <- p1 %>%
  add_trace(
    x = 1, y = 1, z = 0.75,
    type = "scatter3d",
    mode = "markers",
    marker = list(
      size = 16,
      color = "pink",
      opacity = 0.9
    ),
    hoverinfo = "none",
    showlegend = FALSE
  ) %>%
  add_trace(
    x = 1, y = 1, z = 0.75,
    type = "scatter3d",
    mode = "text",
    text = "h",
    textposition = "middle center",
    textfont = list(
      size = 16,
      family = "Helvetica",
      color = "black"
    ),
    hoverinfo = "none",
    showlegend = FALSE
  )
```

```{r}
p1
```

