0

I try to plot a parallel chart, that shows interactions of users while playing an audio file. The one y-axis shows the audio playback, the other axis the time the user is working on it.

Problem: The maximum value of the left TranscrTime-axis should be approx. 6000 and not 600. The max value of the Audio-Axis should be 334. I think there goes something wrong (see screenshot & code).

I'm out of ideas now... What do I do wrong?

enter image description here


# the code to create the data table. An example is uploaded to pastebin at the end of this post.
create_pc_table <- function(id) {
  id_logs <- logs[logs$id == id, ]

  sample_rate <- 22050

  #signal time and transcription time in seconds
  # for reasons of simplicity I inserted the values in the code
  signal_time <- 334
  transcr_time <- 5940

  # ignore all playhead postions less than 0
  playpos_num <- nrow(id_logs[id_logs$playpos > -1,])

  # create data table
  data <-
    data.frame(
      "Audio" = vector(length = playpos_num),
      "TranscrTime" = vector(length = playpos_num),
      "Type" = vector(length = playpos_num)
    )

  j <- 1
  if (is.numeric(signal_time) && is.numeric(transcr_time)) {
    for (i in 1:nrow(id_logs)) {
      log <- id_logs[i,]
      type <- get_log_type(log)

      #ignore audio changes
      if (type != "audioChange") {
        playpos <- as.double(log$playpos)

        if (playpos > -1) {
          audio_scaled = as.double((playpos / sample_rate))
          transcr_scaled = as.double(log$timestamp)

          print(transcr_scaled)
          data[j,] <-
            c(audio_scaled, transcr_scaled, get_log_type(log))
          j <- j + 1
        }
      }
    }
  } else {
    print("value is not numeric!")
  }

  # remove empty lines
  data <- data[data$Audio!=FALSE,]
  return(data)
}

# the code to plot the parallel chart
draw_parallel_chart <- function(id) {
  data <- create_pc_table(id)

  # Plot
  ggparcoord(
    data,
    columns = 1:2,
    groupColumn = 3,
    scale = "globalminmax",
    title = id,
  ) + theme(axis.title.x = element_blank(), axis.title.y = element_blank(), panel.background =element_blank(), panel.grid.major = element_line("black", size=0.2), panel.grid.major.x = element_line("black", size=1, arrow = arrow()), panel.grid.minor.y= element_line("lightgray", size=1)) + scale_x_discrete(expand = c(0.05,0.05))
}

Data Table: https://pastebin.com/KfK4LFAh

julianpoemp
  • 1,965
  • 3
  • 14
  • 29

1 Answers1

0

I fixed it. The problem was that the Audio and the TransrTime columns were not recognized as numerics. I fixed it when I converted all values of the column to numerics:

...
  data[,1] <- as.numeric(data[,1])
  data[,2] <- as.numeric(data[,2])
  data <- data[order(data$TranscrTime),]
  return(data)
}

enter image description here

julianpoemp
  • 1,965
  • 3
  • 14
  • 29