【发布时间】:2020-08-05 04:09:06
【问题描述】:
如何自定义 ggplot2 中面板/子图的位置?
具体来说,我有一个分组的时间序列,我想为每个时间序列生成 1 个子图,并带有子图的自定义位置,不一定在网格中。
facet_grid() 或 facet_wrap() 函数不提供对面板位置的完全自定义,因为它使用网格。
library(tidyverse)
df = data.frame(group = LETTERS[1:5],
x = c(1,2,3,1.5,2.5),
y =c(2,1,2,3,3),
stringsAsFactors = F)%>%
group_by(group)%>%
expand_grid(time = 1:20)%>%
ungroup()%>%
mutate(dv = rnorm(n()))%>%
arrange(group,time)
## plot in grid
df%>%
ggplot()+
geom_line(aes(x=time,y=dv))+
facet_grid(~group)
## plot with custom x, y position
## Is there an equivalent of facet_custom()?
df%>%
ggplot()+
geom_line(aes(x=time,y=dv))+
facet_custom(~group, x.subplot = x, y.subplot = y)
仅供参考:此数据集只是一个示例。我的数据是 EEG 数据,其中每组代表一个电极(最多 64 个),我想根据电极在头部的位置绘制每个电极的 EEG 信号。
【问题讨论】:
标签: r ggplot2 facet-wrap