R - 每行的 gghighlight 颜色
R - gghighlight color for each line
我有一个这种格式的数据框:
df <- data.frame(
id = c(1,1,1,2,2,2,3,3,3,4,4,4),
time = c(1,2,3,1,2,3,1,2,3,1,2,3),
value = c(1,3,5,2,4,6,3,5,7,1,4,7)
)
我想创建单独的绘图,突出显示每个 id
并将其他未突出显示的 ids
阴影显示为灰色。
ggplot(df) +
geom_line(aes(x = time, y = value, color = as.factor(id))) +
gghighlight::gghighlight(id == 4)
我研究了 gghighlight
包,它可以为单行做高亮显示。但是,我希望每个 id (1,2,3,4,etc...)
.
都有一个地块
有没有聪明的方法可以快速做到这一点? facet_grid
能做到吗?
facet_wrap
和 facet_grid
都在 id
上工作。
ggplot(df) +
geom_line(aes(x = time, y = value, color = as.factor(id))) +
gghighlight::gghighlight() +
facet_wrap(~id)
我有一个这种格式的数据框:
df <- data.frame(
id = c(1,1,1,2,2,2,3,3,3,4,4,4),
time = c(1,2,3,1,2,3,1,2,3,1,2,3),
value = c(1,3,5,2,4,6,3,5,7,1,4,7)
)
我想创建单独的绘图,突出显示每个 id
并将其他未突出显示的 ids
阴影显示为灰色。
ggplot(df) +
geom_line(aes(x = time, y = value, color = as.factor(id))) +
gghighlight::gghighlight(id == 4)
我研究了 gghighlight
包,它可以为单行做高亮显示。但是,我希望每个 id (1,2,3,4,etc...)
.
有没有聪明的方法可以快速做到这一点? facet_grid
能做到吗?
facet_wrap
和 facet_grid
都在 id
上工作。
ggplot(df) +
geom_line(aes(x = time, y = value, color = as.factor(id))) +
gghighlight::gghighlight() +
facet_wrap(~id)