I would like to make a red horizontal mean line in a line chart with ggplot2
, but I don't know how to do that. It shouldn't represent the mean of the values of the column E
.
I prove that but it didn't work:
ggplot(data = df3, aes(x = df3$timestamp, y = df3[,1], group = 1)) +
geom_line() +
ylab("values") +
xlab("time") +
geom_hline(yintercept=mean(df3[,1]))
The data frame is called df3
, the x line time series is the column timestamp
, the y line is the column metric E
.
Here the data frame head:
E timestamp
11 -22.30933 2015-02-09 09:05:00.712
14 -22.17142 2015-02-09 09:06:00.703
17 -21.24673 2015-02-09 09:07:00.703
20 -21.58154 2015-02-09 09:08:00.702
23 -21.07082 2015-02-09 09:09:00.702
26 -22.49973 2015-02-09 09:10:00.702