r - How to display 0 value in a bar chart using ggplot2 -


i have data frame called data:

head(data)

     date         total_sold purchasability visibility 81 2014-05-01          3              3          3 82 2014-05-02          2              2          3 83 2014-05-03          1              2          3 84 2014-05-04          1              3          3 85 2014-05-05          3              2          3 86 2014-05-06          0              0          3 

and bar chart x = date , y = total_sold color depending on purchasability. ggplot2 :

bar <- ggplot(data = data, aes(x = date, fill=as.factor(purchasability),y = total_sold)) + geom_bar(stat = 'identity') 

the output nice problem total_sold = 0 there not chart , no way know purchasability. possible still display bar (maybe 0.5 -0.5) when total_sold = 0 ?

thanks

i'm not sure there's simple way go 0.5 -0.5 can show 0 value being fraction (eg -0.1) modifying value in bar= line to:

bar <- ggplot(data = data, aes(x = date, fill=as.factor(purchasability),y = sapply(total_sold, fun=function(x) ifelse(x==0, -0.1,x) ))) + geom_bar(stat = 'identity') 

this produces: enter image description here

it little misleading show 0 other 0, hope solves problem.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -