我正在尝试创建一个线条图来显示一个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 ")# Groups: day [28]
day trialtype mean
<chr> <chr> <dbl>
1 2022-08-06 go 0.497
2 2022-08-06 nogo 0.548
3 2022-08-07 go 0.449
4 2022-08-07 nogo 0.407
5 2022-08-08 go 0.444
6 2022-08-08 nogo 0.350
7 2022-08-09 go 0.443
8 2022-08-09 nogo 0.453
9 2022-08-10 go 0.462
10 2022-08-10 nogo 0.426
# … with 46 more rows编辑:
因此,我使用了您提供的代码(谢谢),但现在我认为存在一个缺少值的问题。
Warning messages:
1: Removed 1 row(s) containing missing values (geom_path).
2: Removed 9 rows containing missing values (geom_point). 发布于 2022-09-23 21:52:26
我试着从照片中复制你的例子,我没有把所有的数字都看清楚,因为我是用手复制的,但是,还是要看一看:
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 ")情节:

下一次,如果可能的话,也许您可以通过github或dput()共享数据,而不是图片(我仍然不知道如何使用dput,但我也被要求通过它上传:)
在Ben的评论之后,我刚刚将group = 2更改为group = trialtype
(很抱歉,我刚在帖子后查看了这条评论,如果这是好的做法,我可能会删除答案,我也是这个论坛的新手)
group = 2上得到的

:)
https://stackoverflow.com/questions/73831489
复制相似问题