I am having some difficulty with the ggplot2 package and the gradient fill. For my data with low number of data points, its gradient and density intensity doesn't really match. Here is an example:
The code I am using is:
pt <- read.xlsx("plots.xlsx", sheetName = "PT1_TB varseq", stringsAsFactors=FALSE)
ggplot(pt, aes(x=pt$BAF, y=pt$LogR) ) +
stat_density_2d(aes(fill = ..density..), geom = "raster", contour = FALSE) +
scale_fill_distiller(palette= "Spectral", direction=-1) +
scale_y_continuous(name="LogR", limits = c(-0.8, 0.6), breaks = seq(-0.8, 0.6, 0.2)) +
scale_x_continuous(name="BAF", breaks = seq(0, 0.8, 0.2)) +
theme(
legend.position='none',
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank(),
axis.line = element_line(colour = "black")
) +
geom_point(aes(shape = factor("cyl")), size = 1) + scale_shape(solid = FALSE)
I would like the gradient to change more abruptly, for example, I would like to see more seperation in colors between points at (0;0.2) and (0.25;-0.2). Furthermore the yellow color in the middle where no points are should be blue.
While I am at it, does anybody know how remove the white gap between the axes and the actual plot?
Thanks in advance :)