【发布时间】:2021-11-17 13:11:40
【问题描述】:
我有一个如下所示的数据集
# # A tibble: 94 × 4
# type shortcut date time
# <chr> <chr> <date> <dbl>
# 1 Three lap No 2010-08-17 24.24
# 2 Three lap No 2010-08-24 38
# 3 Three lap Yes 2010-08-31 32.4
# 4 Single lap No 2010-09-07 20.6
# 5 Single lap No 2010-09-14 39.03
我不知道如何重新创建图中的“Race”变量。我试过了,但它不起作用!
newdata <- records %>%
group_by(type, shortcut) %>%
mutate(race = case_when(
type == "Three lap" && shortcut == "No" ~ "Three lap with no shortcut",
type == "Three lap" && shortcut == "Yes" ~ "Three lap with shortcut",
type == "Single lap" && shortcut == "No" ~ "Single lap with no shortcut",
type == "Single lap" && shortcut == "Yes" ~ "Single lap with shortcut"))
ggplot(data = newdata, mapping = aes(x = date, y = time, color = race)) +
geom_line() +
geom_point()
对我应该尝试什么有什么建议吗?
【问题讨论】:
-
如果您通过包含可用格式的数据来使您的问题可重现,例如将
dput(records)的输出粘贴到问题中以启用对可能解决方案的测试和验证,则更容易为您提供帮助。 Link for guidance on asking questions
标签: r ggplot2 group-by dplyr data-wrangling