2017-06-14 23 views
0

這是我使用的代碼 -ggplot geom_col不會躲閃的時間序列數據

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變量堆疊,而不是由側方迴避。 Web上的許多示例都沒有直接與時間序列數據(X軸)相關,而是與少數幾個類別有關/我的旋轉數據的嘗試最多是混亂的,並且不起作用。

+1

請[編輯]你的問題,並提供數據重現您的問題。見[mcve]。 – Uwe

回答

0

這個怎麼樣,你融化你的數據並繪製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'))