Im trying to stack histograms for different subgroups. Here is my data.table:
> head(result)
persnr year diff
1: 61961225 1994 22.52241
2: 62037645 1994 22.52241
Here is the structure:
> str(result)
Classes ‘data.table’ and 'data.frame': 25213 obs. of 3 variables:
$ persnr: num 61961225 62037645 62181514 62499451 62649247 ...
$ year : int 1994 1994 1994 1994 1994 1994 1994 1994 1994 1994 ...
$ diff : num 22.5 22.5 22.5 22.5 22.5 ...
- attr(*, ".internal.selfref")=<externalptr>
I try to create overlapping histograms, where year
identifies the subgroups. I tried to follow two different answers: [1] and [2], but both lead to the same error - which is not googleable. Whats wrong with my data / what do I need to adapt?
> ggplot(result, aes(x=diff, fill=year)) + geom_histogram(position='identity')
stat_bin: binwidth defaulted to range/30. Use 'binwidth = x' to adjust this.
Error in grid.Call.graphics(L_raster, x$raster, x$x, x$y, x$width, x$height, :
Empty raster
ggplot(result) + geom_histogram(aes(x=diff, fill=year), position='dodge')
stat_bin: binwidth defaulted to range/30. Use 'binwidth = x' to adjust this.
Error in grid.Call.graphics(L_raster, x$raster, x$x, x$y, x$width, x$height, :
Empty raster