我有幾次測量,每次測量花費的時間不同(5 秒、8 秒等)
我想將這些測量值分組為例如折線圖,但將時間(x 軸)縮放到 0-100%,以便這些測量值均勻分布。
下面是一個例子:
library(tidyverse)
measurement <- c("first", "second", "third", "fourth")
group <- c("A", "B", "A", "B")
time_1 <- c("1", "2", "1", NA)
time_2 <- c(NA, "3", NA, "4")
time_3 <- c("10", "15", "17", "19")
time_4 <- c("5", NA, "8", NA)
time_5 <- c("1", "2", "1", "1")
time_6 <- c("3", NA, NA, NA)
time_7 <- c("4", NA, NA, NA)
time_8 <- c("2", NA, NA, NA)
test_plot <- data.frame(measurement, group, time_1,
time_2, time_3, time_4, time_5, time_6, time_7,
time_8)
gather_testplot <- gather(test_plot, key="time", value="value",
"time_1", "time_2", "time_3", "time_4", "time_5",
"time_6", "time_7", "time_8")
gather_testplot_nona <- gather_testplot %>%
drop_na(value)
gather_testplot$time <- as.numeric(as.character(gather_testplot$time))
ggplot(gather_testplot_nona, aes(x=time, y=value, color=group,
group=interaction(group)))
geom_line()

轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/348075.html
