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

R 1列带条形图,其他3列为同一图表上的线条,r,plotly,r-plotly,ggplotly,R,Plotly,R Plotly,Ggplotly,我有一个数据框,其中包含x轴的日期,并希望将计数绘制为条形图(垂直),将平均值、下_形态和上_形态绘制为水平线。下面是我的数据帧 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-

我有一个数据框,其中包含x轴的日期,并希望将计数绘制为条形图(垂直),将平均值、下_形态和上_形态绘制为水平线。下面是我的数据帧

   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)) 

使用
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))