【问题标题】:ggplot geom_col won't dodge time series dataggplot geom_col 不会躲避时间序列数据
【发布时间】:2017-06-14 20:03:33
【问题描述】:

这是我正在使用的代码 -

  g.volume <- ggplot (time_series, aes(x=quotedate, y=cv)) +  
            geom_col(position='dodge',fill='steelblue1', size=.8)      +
             geom_col(aes(x=quotedate, y=pv) ,position='dodge', fill='hotpink1', size=.8) +

  labs(x = "", y = "Call / Put  Volume") + theme_bw() +
  theme(axis.ticks.x=element_blank(), axis.text.x=element_blank())  +  
  theme(panel.grid.major = element_line(colour = "grey", size=.5,linetype = 'dashed'))

输出在数值上是正确的,但两个 Y 变量是堆叠的,而不是并排躲避。网络上的许多示例都没有直接与时间序列数据(X 轴)相关,而是与少数类别相关/我尝试旋转数据的尝试充其量是混乱的,并且不起作用。

【问题讨论】:

标签: r ggplot2


【解决方案1】:

这个怎么样,你融化你的数据并绘制value

dat <- melt(df, id.vars = c("quotedate"))
ggplot(data=dat,aes(x= quotedate, y=value, fill=variable, color=variable)) +
  geom_bar(stat="identity",position ="dodge")+
  labs(x = "", y = "Call / Put  Volume") + theme_bw() +
  theme(axis.ticks.x=element_blank(), axis.text.x=element_blank())  +  
  theme(panel.grid.major = element_line(colour = "grey", size=.5,linetype = 'dashed'))

【讨论】:

    猜你喜欢
    • 2014-11-05
    • 2018-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-09
    • 2018-11-11
    • 2020-06-29
    • 1970-01-01
    相关资源
    最近更新 更多