ggplot facet_grid data.table order bug

170 views Asked by At

When I try to use ggplot together with data.table I discovered an odd behaviour which seems to be a bug.

Depending on the order of the rows I set in my data.table (using setkey(data,V1,V2..)), facet_grids differ completely.

Here is an example of the working facet_grid:

  setkey(dat.rel,FINISH_TIME_BUFFER) #Set Order of Rows according t FINISH_TIME_BUFFER
  ggplot(dat.rel)+                        #Make Plot
  aes(x=dat.rel$INdex,y=dat.rel$GWorkerMissing)+
  scale_colour_gradientn(colours=rainbow(10),trans="log",breaks=c(1,100,500,10000))+
  geom_point(aes(color=dat.rel$MAX_RUNTIME_IN_SECONDS),size=10,alpha=0.7)+
  facet_grid( ~ dat.rel$FINISH_TIME_BUFFER)+
  geom_text(aes(label=dat.rel$FINISH_TIME_BUFFER),size=4)

That is the result:

https://mathtec-my.sharepoint.com/personal/c_roehl_mathtec_at/_layouts/15/guestaccess.aspx?docid=160377f61360e41c3b4e9accf8b003c24&authkey=AV1U9O-wqZGlCLaRkQyDPUE

If I now substitute the first line with

setkey(dat.rel,INdex)

which orders the data.table by an Index, the result is the following:

https://mathtec-my.sharepoint.com/personal/c_roehl_mathtec_at/_layouts/15/guestaccess.aspx?docid=10a459006c5c74c9d9782cbfeedba56d2&authkey=Ad9Ncb76P0IqkJN9iroTy7Y

As you can see on the geom_text on every point, the FINISH_TIME_BUFFER is not assigned correctly to the respective grid.

It seems that there is a Bug in ggplot, but to be sure that it's not my fault I give it a try here.

1

There are 1 answers

0
EddyXorb On BEST ANSWER

Just remove all dat.rel$ inside the plot configuration makes the facet_grids work like desired, indipendently from the row order.