我正在嘗試創建一個折線圖,顯示幾周內不進行試驗的回應時間。但是,我不想在 x 軸上顯示日期,而是希望它按“第 1 天,第 2 天”等順序顯示......在聽取了另一個用戶的建議后,我將其添加到了我的 ggplot 代碼中
mutate(days = paste0("day",row_number()))
完整的ggplot代碼如下:
p03_dropped_rt %>%
mutate(days = paste0("day",row_number())) %>%
ggplot(aes(x = fct_inorder(days), y = mean, group = trialtype))
geom_line(aes(color = trialtype))
geom_point(aes(color = trialtype))
theme(axis.text.x = element_text(angle = 60, vjust = 0.5))
labs(title=" P03s Average response time of Go/No-go Trials",
x = "Day of training",
y = "Average Response Time ",
color = "Trial Type")
我認為這會將日期更改為天并按順序排列,但是,生成的可視化是錯誤的(參見圖片以進行澄清)
我只是想知道是否有人對如何解決這個問題有任何想法?
這是資料:
structure(list(day = structure(c(18880, 18880, 18908, 18908,
18911, 18912, 18912, 18913, 18913, 18914, 18914, 18915, 18915,
18916, 18916, 18917, 18917, 18918, 18918, 18919, 18920, 18921,
18921, 18922, 18922, 18923, 18924), class = "Date"), trialtype = c("go",
"nogo", "go", "nogo", "go", "go", "nogo", "go", "nogo", "go",
"nogo", "go", "nogo", "go", "nogo", "go", "nogo", "go", "nogo",
"go", "go", "go", "nogo", "go", "nogo", "go", "go"), mean = c(0.453363414634146,
0.21005, 0.63720350877193, 0.8809, 0.624077192982456, 0.581956842105263,
0.63065, 0.588196842105263, 0.607075, 0.540253289473684, 0.73215,
0.529153097345133, 0.583133333333333, 0.538794736842105, 0.4409,
0.522421428571429, 0.4792, 0.552129824561403, 0.5282, 0.512742105263158,
0.473664912280702, 0.528580701754386, 0.544266666666667, 0.490643859649123,
0.49955, 0.440738596491228, 0.475708771929825)), class = c("grouped_df",
"tbl_df", "tbl", "data.frame"), row.names = c(NA, -27L), groups = structure(list(
day = structure(c(18880, 18908, 18911, 18912, 18913, 18914,
18915, 18916, 18917, 18918, 18919, 18920, 18921, 18922, 18923,
18924), class = "Date"), .rows = structure(list(1:2, 3:4,
5L, 6:7, 8:9, 10:11, 12:13, 14:15, 16:17, 18:19, 20L,
21L, 22:23, 24:25, 26L, 27L), ptype = integer(0), class = c("vctrs_list_of",
"vctrs_vctr", "list"))), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -16L), .drop = TRUE))
折線圖圖片:
uj5u.com熱心網友回復:
看起來p03_dropped_rt是按天分組的,所以當您應用您的 時mutate,它將每個“go”試驗標記為第 1 天,每個“nogo”試驗標記為第 2 天。相反,我們可以按試驗型別分組,按天排列,然后變異:
p03_dropped_rt %>%
group_by(trialtype) %>%
arrange(day) %>%
mutate(days = paste0("day",row_number())) %>%
ggplot(aes(x = fct_inorder(days), y = mean, group = trialtype))
geom_line(aes(color = trialtype))
geom_point(aes(color = trialtype))
theme(axis.text.x = element_text(angle = 60, vjust = 0.5))
labs(title=" P03s Average response time of Go/No-go Trials",
x = "Day of training",
y = "Average Response Time ",
color = "Trial Type")

轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/523448.html
標籤:rggplot2线形图
