"Error in unit(tic_pos.c, "mm") : 'x' and 'units' must have length > 0" while using the qplot() function in R

r
datavisualization
ggplot2

#1

Hello,

I was reading through a tutorial on ggplot2 and I tried to plot some data using the qplot() function as->

qplot(count,data=train,fill=season,geom=“bar”)

and I am getting an error->

stat_bin: binwidth defaulted to range/30. Use ‘binwidth = x’ to adjust this.
Error in unit(tic_pos.c, “mm”) : ‘x’ and ‘units’ must have length > 0

Even after changing the binwidth I am getting->

Error in unit(tic_pos.c, “mm”) : ‘x’ and ‘units’ must have length > 0

How to tackle this error and remove it?

Thanks


#2

Hello @adityashrm21,

You are getting this error because your season variable is numeric. You need to convert it into factor and then use qplot as you need discrete values for fill= as bars will be stacked and colored according to season.

So use-

qplot(count,data=train,fill=as.factor(season),geom=“bar”)

and see if it works!