更改facet_grid内单个图的线条大小

时间:2018-11-07 10:36:57

标签: r ggplot2

我想在单个facet_grid中更改特定行的大小,并保持其他行不变。这是为了“突出显示”更多行。

假数据:

set.seed(123)
my_data <- data.frame(
  time = 1:100,
  a = runif(100, min = 0, max = 10),
  b = runif(100, min = 0, max = 20),
  c = runif(100, min = 0, max = 30)
)


library(ggplot2)
library(dplyr)
my_data %>% 
  gather("key", "value", -time) %>%
  ggplot(aes(x = time, y = value, color = key)) +
  geom_line() +
  facet_grid(key~., scales = "free") +
  theme_minimal() +
  guides(color = FALSE, size = FALSE)

enter image description here

在此示例中,我希望b情节具有更大的线size

1 个答案:

答案 0 :(得分:2)

这可以通过创建具有重复大小的新矢量来实现:

linesize = rep(c(0, 1, 0), each=100) # externally define the sizes
# note that a,c will have size=0 while b size=1

这将在geom_line调用中使用:

my_data %>% 
  gather("key", "value", -time) %>%
  ggplot(aes(x = time, y = value, color = key)) +
  geom_line(size = linesize) + # here we can pass linesize
  facet_grid(key~., scales = "free") +
  theme_minimal() +
  guides(color = FALSE)

enter image description here