I am using R to solve an equation with two variables in R. I am varying the two variables by a sequence and then using geom_raster with interpolation to generate a plot of solutions.
However, when I plot the data I noticed that the plot area exceeds the range of the y-axis values that I give as input.
If I use ylim to impose a limit on the area, then the interpolated plot shrinks and no longer bounds the values. If I use vjust = 0, then the top of the plot bounds the area, but the bottom does not.
My code for a reproducible example is as follows:
library(ggplot2)
library(reshape2)
x_range <- seq(0.001,10, by=0.001)
y_range <- (seq(1*10^-10, 1*10^-9, by = 1*10^-10))
FUN <- function(x, y) log10((1)/(x*y))
data <- outer(x_range, y_range, FUN)
colnames(data) <- y_range
rownames(data) <- x_range
melted_data <- melt(data)
p <- ggplot(data=melted_data)
# basic plot
p + geom_raster(aes(x=Var1, y=Var2, fill=value), interpolate = TRUE) +
geom_hline(yintercept = 1*10^-10) +
geom_hline(yintercept = 1*10^-9)
# with imposed ylim
p + geom_raster(aes(x=Var1, y=Var2, fill=value), interpolate = TRUE) +
geom_hline(yintercept = 1*10^-10) +
geom_hline(yintercept = 1*10^-9) +
ylim(1*10^-9, 1*10^-10)
# with modified vjust
p + geom_raster(aes(x=Var1, y=Var2, fill=value), interpolate = TRUE, vjust = 0) +
geom_hline(yintercept = 1*10^-10) +
geom_hline(yintercept = 1*10^-9)
I would like the final plot to bound the actual data given (specified by the two horizontal lines at y = 1*10^-9 and y = 1*10^-10.
I think what I am observing is due to the interpolated pixel size, but I am not sure.