2017-04-03 64 views
0

我生成從數據柱狀圖是按以下格式:分配連續填充顏色geom_bar

count | month 
------|----------- 
1000 | 2012-01-01 
10000 | 2012-02-01 

我試圖分配連續的顏色我的條形圖。我想要一個顏色漸變用作條的填充顏色。

我想這一點:

ggplot(userData, aes(month, count)) + 
    geom_bar(stat = "identity") + 
    scale_x_date() + 
    # scale_fill_gradient(low="blue", high="red") + 
    scale_fill_continuous(low="blue", high="red", limits=c(0,6500000)) + 
    labs(x= "Time", y="Count") 

但是,我沒有得到期望的結果和圖表中的酒吧仍然停留灰色作爲可以看到下面:

rplot

我已嘗試使用scale_fill_continuousscale_fill_gradient,但都沒有成功。

我不確定我在這裏錯過了什麼。

+0

@GGamba感謝您的快速回復。它似乎工作。你能把它作爲答案嗎? –

回答

3

你還沒有分配填充美學的任何東西:aes(month, count, fill = count)應該做的伎倆。

完整代碼:

ggplot(userData, aes(month, count, fill = count)) + 
    geom_bar(stat = "identity") + 
    scale_x_date() + 
    scale_fill_continuous(low="blue", high="red") + 
    labs(x= "Time", y="Count") 

(限制,現在可能是無用的,但隨時將它們添加回)