r - 更改 facet_grid 内单个图的线条大小
问题描述
我想在单个 内更改特定行的大小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
情节有一个更大的 line size
。
解决方案
这可以通过创建一个具有重复大小的新向量来实现:
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)
推荐阅读
- javascript - React/Redux App 停止处理 MapDispatchToProps 函数
- angular - Angular/NGXS,基于失败的 API 请求测试操作时遇到问题
- r - Scholar 软件包的问题 (scholar::get_article_cite_history)
- node.js - 如何编写可以再次调用的干净异步请求
- python - PySide2 在访问 QObject::property() 时崩溃
- mql4 - 当收盘价交叉并收于某个移动平均线上方至已知摆动低点和摆动高点时,如何计算多少根柱线?
- osgi - OSGI EventAdmin 无法发送事件 - 在 Producer 上获取空点异常
- python - 从 python 生成具有列表中两列的 excel 文件
- jquery - 使用 switchClass 将父类悬停在子类上,但不影响具有同一类的其他 div
- javascript - 通过两个文本查找一个元素