如何在 ggplot 制作的 barplot 中标记阈值线?
How to label under threshold line in barplot made in ggplot?
我有一个条形图如下:
data <- data.frame(
name=letters[1:5],
value=sample(seq(4,15),5)
)
data
数据如下:
name value
a 5
b 6
c 14
d 15
e 7
我使用 ggplot 在点 10
上绘制了条形图
ggplot(data) +
geom_bar( aes(x=name, y=value), stat="identity", fill="skyblue", alpha=0.7) +
geom_hline(yintercept = 10,color = "red", linetype = "solid")
我想在上方添加标签 high
,在下方添加标签 low
,在 10
上添加标签 normal
您可以使用注释:
ggplot(data) +
geom_bar( aes(x=name, y=value), stat="identity", fill="skyblue", alpha=0.7) +
geom_hline(yintercept = 10,color = "red", linetype = "solid") +
annotate("text", x = "e", y = 10.5, label = "high") +
annotate("text", x = "e", y = 10, label = "normal") +
annotate("text", x = "e", y = 9.5, label = "low")
我有一个条形图如下:
data <- data.frame(
name=letters[1:5],
value=sample(seq(4,15),5)
)
data
数据如下:
name value
a 5
b 6
c 14
d 15
e 7
我使用 ggplot 在点 10
ggplot(data) +
geom_bar( aes(x=name, y=value), stat="identity", fill="skyblue", alpha=0.7) +
geom_hline(yintercept = 10,color = "red", linetype = "solid")
我想在上方添加标签 high
,在下方添加标签 low
,在 10
上添加标签 normal
您可以使用注释:
ggplot(data) +
geom_bar( aes(x=name, y=value), stat="identity", fill="skyblue", alpha=0.7) +
geom_hline(yintercept = 10,color = "red", linetype = "solid") +
annotate("text", x = "e", y = 10.5, label = "high") +
annotate("text", x = "e", y = 10, label = "normal") +
annotate("text", x = "e", y = 9.5, label = "low")