R 1 列带条形图,其他 3 列作为同一图表上的线条

R 1 column with bar chart the other 3 as lines on the same chart

我有一个带有 x 轴日期的数据框,我想将计数绘制为条形图(垂直),将平均值 lower_conf 和 upper_conf 绘制为水平线。以下是我的数据框。

   Date        Count  Mean      X95_lower_conf  X95_upper_conf
0  2018-11-01  1      5.225806  1.494764        8.956849
1  2018-11-02  0      5.225806  1.494764        8.956849
2  2018-11-03  21     5.225806  1.494764        8.956849
3  2018-11-04  1      5.225806  1.494764        8.956849
4  2018-11-05  0      5.225806  1.494764        8.956849
5  2018-11-06  0      5.225806  1.494764        8.956849

我尝试了很多不同的方法来完成这个,但我遇到了问题,这是我尝试过的方法:

plot_ly(df1, x = ~Date, y = ~Mean, name = 'Mean') %>%
  add_trace(y = ~X95_upper_conf, name = 'Upper Confidence', type = 'scatter', mode = 'lines') %>%
  add_trace(y = ~X95_lower_conf, name = 'Lower Confidence', type = 'scatter', mode = 'lines') %>%
  add_trace(y = ~Count, name = 'Count', type = 'bar',mode = 'lines')

如果能帮助我调整它以获得我想要的输出,我们将不胜感激!

使用ggplot2:

library(ggplot2)

ggplot(df1) +
  geom_col(aes(Date, Count)) +
  geom_hline(aes(yintercept = Mean)) +
  geom_hline(aes(yintercept = X95_lower_conf)) +
  geom_hline(aes(yintercept = X95_upper_conf))