Error: Discrete value supplied to continuous scale


#1

Hi
Can anyone please see why the error occurs?

ggplot(moviedata, aes(x= year, y=screens))+
stat_boxplot(geom= 'errorbar')+
geom_boxplot()+
theme_bw()+
labs(title = "movie Genre by the year")+
xlab("year")+
ylab("genre")+
ylim(5,25)
Error: Discrete value supplied to continuous scale


#2

Hard to tell w/o knowing what your data looks like, but I suspect screens is stored as a factor or character. What does str(moviedata) tell you?


#3
> str(moviedata)
'data.frame':	231 obs. of  15 variables:
 $ movie              : Factor w/ 231 levels "13 Sins","22 Jump Street",..: 1 2 3 4 5 6 7 8 9 10 ...
 $ year               : int  2014 2014 2014 2014 2014 2014 2014 2014 2014 2014 ...
 $ ratings            : num  6.3 7.1 6.2 6.3 4.7 4.6 6.1 7.1 6.5 6.1 ...
 $ genre              : int  8 1 1 1 8 3 8 1 10 8 ...
 $ gross              : int  9130 192000000 30700000 106000000 17300000 29000 42600000 5750000 26000000 48600000 ...
 $ budget             : Factor w/ 105 levels "100000","1000000",..: 68 77 56 7 64 75 69 42 56 12 ...
 $ screens            : Factor w/ 201 levels "103","1044","1061",..: 176 111 69 126 34 201 92 196 52 33 ...
 $ sequel             : int  1 2 1 2 2 1 1 1 1 1 ...
 $ dummy_sequel       : int  NA 1 NA 1 1 NA NA NA NA NA ...
 $ sentiment          : int  NA 2 NA NA NA NA NA 2 3 NA ...
 $ views              : int  3280543 583289 304861 452917 3145573 91137 3013011 1854103 2213659 5218079 ...
 $ likes              : int  4632 3465 328 2429 12163 112 9595 2207 2210 11709 ...
 $ dislikes           : int  425 61 34 132 610 7 419 197 419 532 ...
 $ comments           : int  636 186 47 590 1082 1 1020 593 382 770 ...
 $ aggregate_followers: Factor w/ 191 levels "10070000","10280000",..: 10 20 136 145 61 108 172 27 22 73 ...
>

#4

the field screens is being stored as discrete values (Factors). You can't create a boxplot where the y data is discrete. If the data in screens can be converted to a number, you should do so. But you should really look at the data to make sure that makes sense.