【发布时间】:2021-06-14 06:36:07
【问题描述】:
我有一个按面绘制和分隔的数据库。第一行(a 行)的刻面需要 0.5 处的水平线,而第二行(b 行)的刻面需要 1 处的线。在this example 之后,我已经部分实现了我的目标。但是,0.5 和 1 处的水平线出现在所有方面。
library(ggplot2)
#Data
values <- c(0.4, 0.6, 0.9, 1.1)
Column <- c("UW", "LW", "UW", "LW")
Row <- c("a", "a", "b", "b")
DF <- data.frame(Row, Column, values)
DF$Column <- factor(DF$Column,
levels = c("UW", "LW"))
DF$Row <- factor(DF$Row,
levels = c("a", "b"))
#Auxiliar DF
Target <- c("a", "b")
Lines <- c(0.5, 1)
Lines_in_plot <- data.frame(Target, Lines)
Lines_in_plot$Target <- factor(Lines_in_plot$Target)
#Plot
ggplot(data = DF, aes(y = values)) +
geom_bar() +
facet_grid(Row~Column,
scales = "free") +
geom_hline(data = Lines_in_plot,
yintercept = Lines,
linetype = "dashed",
color = "red")
此 MWE 运行但显示以下警告消息:
geom_hline(): Ignoring `data` because `yintercept` was provided.
【问题讨论】:
-
如果从 geom_hline 中减少 data=Lines_in_plot 部分会发生什么
-
修复了错误但没有修复分割线...
标签: r ggplot2 facet geom-hline