簡體   English   中英

線在 R 的折線圖中沒有完全連接

[英]Lines do not fully connect in line graph in R

我正在嘗試創建一個顯示 Go/No-go 任務的響應時間的折線圖。 我遇到了線路問題,因為它們沒有連接到預期值。 我只希望“通過”都是一條線,而“禁止”是一條線。 有誰知道如何糾正這個? 我已經包含了折線圖當前的外觀和數據集的示例。 謝謝你!

在此處輸入圖像描述在此處輸入圖像描述

> ggplot(response_times, aes(x = day, y = mean, group = 2)) +
  geom_line(aes(color = trialtype)) +
  geom_point(aes(color = trialtype)) +
  theme(axis.text.x = element_text(angle = 60)) +
  labs(title="Average response time of Go/No-go Trials",
       x = "Date of training",
       y = " Average Response Time ")

我試圖從照片中復制你的例子,我沒有得到所有的數字,因為我是手工復制的,但是,還是看看:

day <- rep(c("2022-06", "2022-07", "2022-08", "2022-09", 
             "2022-10", "2022-11", "2022-12", "2022-13",
             "2022-14", "2022-15", "2022-16", "2022-17", 
             "2022-18", "2022-19", "2022-20", "2022-21"))
trialtype <- as.factor(rep(c("go", "no-go"), 16, by = 2))
# mean <- data$CONT_Y[1:8]
mean <- c(0.49, 0.54, 0.44, 0.40, 0.44, 0.34, 0.45, 0.46,
          0.42, 0.47, 0.46, 0.45, 0.26, 0.47, 0.41, 0.48)

mydata <- data.frame(day = day,
                     trialtype = trialtype,
                     mean = mean)

mydata %>% 
  ggplot(., aes(x = day, y = mean, group = trialtype)) +
  geom_line(aes(color = trialtype)) +
  geom_point(aes(color = trialtype)) +
  theme(axis.text.x = element_text(angle = 60)) +
  labs(title="Average response time of Go/No-go Trials",
       x = "Date of training",
       y = " Average Response Time ")

plot:

陰謀

下次,如果可能的話,而不是圖片,那么也許你可以通過 github 或 dput() 分享 dataframe (我仍然不知道如何使用 dput,但我也被要求通過它上傳: )

根據 Ben 的評論,我剛剛將group = 2更改為group = trialtype

(對不起,我發帖后剛剛檢查了評論,如果好的做法我可能會刪除答案,我也是論壇的新手)

  • 編輯:按照 Ben 的建議,這就是你使用group = 2得到的

組2

:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM