我画了一张线条图。我已经在图上添加了一条水平线。怎么把横线打成红色虚线?
# 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)发布于 2019-07-24 15:41:49
要使水平线变为虚线和红色,应在geom_hline函数调用中包含以下参数:
linetype = 'dotted', col = 'red'
# 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, linetype='dotted', col = 'red')+
annotate("text", x = "Feb", y = 40, label = "Previous Level", vjust = -0.5)

https://stackoverflow.com/questions/57177608
复制相似问题