小编Ana*_*han的帖子

如何在ggplot中添加带有标签的水平虚线

我已经绘制了一个线图。我在图上添加了一条水平线。如何取水平线红色虚线?

# Sample Data 

library(tidyverse)
Month= c("Jan","Feb","Mar","Apr","May","Jun")
a = c(11,10,9,8,4,8)

test= data_frame(Month,a) 
test$cum_total <- cumsum(test$a)

test$Month <- factor(test$Month, month.abb)

# ggplot

ggplot(data=test, aes(x=Month, y=cum_total, group=1)) +
  geom_line()+
  geom_point()+
  geom_hline(yintercept=40)+
  annotate("text", x = "Feb", y = 40, label = "Previous Level", vjust = -0.5)
Run Code Online (Sandbox Code Playgroud)

r ggplot2

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

ggplot2 ×1

r ×1