1

I'm trying to make a secondary axis graph with ggplot2, but after running it I get this error

(Error in seq.default(range[1], range[2], length.out = self$detail) : 'from' must be a finite number)

Can someone help me to solve it? My code looks like:

g3=ggplot(IBOCA_Nowcast[IBOCA_Nowcast$month=="febrero",],aes(x=date))+
geom_line(aes(y=NowCast12pm25, colour="Nowcast 12h"), size=0.1) +facet_wrap(~site,scales="free_y")+theme_bw()+
geom_line(aes(y=MM24h,colour="media movil 24h"), size=0.1)+facet_wrap(~site,scales="free_y")+theme_bw()+
geom_line(aes(y=Iboca_24h,colour="Iboca_24h"),size=0.1)+facet_wrap(~site,scales="free_y")+theme_bw()+
geom_line(aes(y=Iboca_NC,colour="Iboca_NC_12h"),size=0.1)+facet_wrap(~site,scales="free_y")+theme_bw()+
scale_y_continuous(sec.axis = sec_axis(~.,name="Iboca_24h"))+facet_wrap(~site,scales="free_y")+theme_bw()
user438383
  • 5,716
  • 8
  • 28
  • 43
  • 2
    Welcome. Please provide a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) of your data using ``dput()``. Thank you. – user438383 Jun 17 '22 at 16:45
  • Also, you can remove all the additional ``facet_wrap`` and ``theme_bw()`` calls - you only need them once. – user438383 Jun 17 '22 at 16:47

1 Answers1

0

I had a similar problem caused by facet_wrap (Error in seq.default(pos[i], length.out = nrows[i]) : 'from' must be a finite number) and the reason was an integer overflow, i.e., the number of elements in the data frame was larger than 2,147,483,647. The solution for me was to reduce the size of the data frame so that nrow(df)*ncol(df) < 2,147,483,647.

kurpav00
  • 138
  • 6