我想在单个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)
在此示例中,我希望b
情节具有更大的线size
。
答案 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)