r - 如何在不正确缩放的情况下绘制平行图表?
问题描述
我尝试绘制一个平行图表,显示用户在播放音频文件时的交互。一个 y 轴显示音频播放,另一个轴显示用户工作的时间。
问题:左侧 TranscrTime 轴的最大值应约为。6000 而不是 600。Audio-Axis 的最大值应该是 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))
}
解决方案
推荐阅读
- sql - 抑制Oracle sql中的重复值
- apache-spark - 是否有允许附加列的数据存储格式?
- python - 如果已经存在,则增加目录名称
- android - 如何发布只能通过链接获得的应用程序?
- html - Django-Template:点击列表项并制作详细信息页面
- postgresql - 从 csv 复制到具有 id 序列列自动递增 PSQL 的表中
- python - Keras中的顺序模型是什么意思
- python-3.x - 如何使用for循环为熊猫数据框附加整行
- amazon-web-services - AWS ECS 中的 fs.file-max 和 ulimit nofile 是否受 EC2 的 fs.file-max 和 nofile 限制?
- python - 包含所有详细信息的 github 存储库