我想創建速度與時間的“單線圖”。我希望根據categ.
categ 是一個因子變數,可以取值 - 0、1、2。
但我得到了基于的三線圖 categ

library(tidyverse)
tbl <- tibble(time = 1:100,
speed = 20 runif(100),
categ = factor(rbinom(n = 100, size = 3, prob = 0.1)))
ggplot(data = tbl,
aes(x = time,
y = speed,
color = categ))
geom_line(size = 1)
theme_bw()
uj5u.com熱心網友回復:
為此,不同顏色的段需要屬于相同的group:
ggplot(data = tbl,
aes(x = time, y = speed, color = categ, group = 1))
geom_line(size = 1)
theme_bw()

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