# S Extra info -------------------------------------------------------------
# Extra Tip
Colors <- rainbow( 5 )
Breaks <- c(0, 1, 3, 5, 7, 10)
p <-
ggplot(a, aes(x = x, y =y)) +
annotation_custom(g, xmin= -0.5 , xmax= 1.25, ymin= -0.25, ymax= 1.25) +
stat_density2d(data= a,
aes(x= x, y=y , fill = factor( cut(..level.. , breaks = c(0, 1, 3, 5, 7, 10)) ) ), # Transform levels to factor and deffine the breaks...
size= 10, bins= 50, geom='polygon') +
geom_point(data= a, aes(x=x, y=y),
color="black", position=position_jitter(w=0.01,h=0.01), alpha=0.1) +
theme_bw() +
scale_fill_manual(values = Colors , breaks = Breaks, guide = F) + # We lost the guide
xlim(0, 1) +
ylim(0, 1)
print(p)
jpeg(filename = "Happy with density plot by ranges.jpeg", res = 100,
width = 18, height =10 ,units = "cm")
print(p)
dev.off()
# annotation_custom(g, xmin= -Inf , xmax=Inf, ymin=-Inf, ymax=Inf) # Así ocupa todo
# S Extra info -------------------------------------------------------------