I have a RasterStack with several 400MB raster files and I want to compare them among each other with the rasterVIS density function. The problem is that the labels of the plot overlap each other. Plot looks similar to this...

So is it possible to change the labels inside a rasterVis density plot to a legend on the side?
I tried things like
library(raster)
library(rasterVis)
Rasterstack = stack(Rasterfile1,Rasterfile2,Rasterfile3,Rasterfile4)
labels = names(RasterStack)
densityplot(RasterStack, xlab="density", ylab="value",
auto.key= list(space="right", lines=TRUE, text=labels))
#or just#
densityplot(RasterStack, xlab="density", ylab="value", auto.key=T)
I also tried the solution mentioned here, but it is not functional for me because it generates vector sizes which are not processible. Any ideas?
Found the solution by adapting the RasterVis Source Code of the density plot function.