Closed
Description
Hi,
I think I found a bug case where data.table does not work with ggplot.
Here's an example:
dt = data.table()
dt[, x := seq(1,100)]
dt[, y := seq(100,1)]
head(dt)
x y
1: 1 100
2: 2 99
3: 3 98
4: 4 97
5: 5 96
6: 6 95
# generate ggplot
ggplot(dt, aes(x,y)) + geom_point()
Error in `$<-.data.frame`(x, name, value) :
replacement has 1 row, data has 0
A workaround was
dt %>% setDF %>% setDT # convert to DF and convert it back
ggplot(dt, aes(x,y)) + geom_point() # now it works
which doesn't seem convenient.
I'm not certain if it is coming from data.table
or ggplot
, for plot(dt)
just works fine, but I guessed it was from data.table
side because setDT
somehow resolves the issue. Or was I naive to use empty data.table
from scratch?