如何在不正确缩放的情况下绘制平行图?
How to plot parallel chart without scaling correctly?
我尝试绘制一个平行图表,显示用户在播放音频文件时的交互。
一个 y 轴显示音频播放,另一个轴显示用户正在处理它的时间。
问题:左TranscrTime轴的最大值应该是大约。 6000 而不是 600。音频轴的最大值应为 334。
我认为出了点问题(见屏幕截图和代码)。
我现在没主意了...我做错了什么?
# 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))
}
数据Table:https://pastebin.com/KfK4LFAh
我修好了。问题是 Audio 和 TransrTime 列未被识别为数字。我在将列的所有值转换为数字时修复了它:
...
data[,1] <- as.numeric(data[,1])
data[,2] <- as.numeric(data[,2])
data <- data[order(data$TranscrTime),]
return(data)
}
我尝试绘制一个平行图表,显示用户在播放音频文件时的交互。 一个 y 轴显示音频播放,另一个轴显示用户正在处理它的时间。
问题:左TranscrTime轴的最大值应该是大约。 6000 而不是 600。音频轴的最大值应为 334。 我认为出了点问题(见屏幕截图和代码)。
我现在没主意了...我做错了什么?
# 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))
}
数据Table:https://pastebin.com/KfK4LFAh
我修好了。问题是 Audio 和 TransrTime 列未被识别为数字。我在将列的所有值转换为数字时修复了它:
...
data[,1] <- as.numeric(data[,1])
data[,2] <- as.numeric(data[,2])
data <- data[order(data$TranscrTime),]
return(data)
}