I am trying to place images to a plot that needs to have fixed coordinates (x, y values are GPS coordinates and I want the map to scale correctly). If the ranges of x and y don't match the images are flatted.
I don't know if this is a bug or desired behavior. Is there a way how to make the image with original aspect ratio? The only thing that I came up with is to put invisible points to the corners to make the plot square again.
Simple example is as following:
require(tidyverse)
require(ggimage)
plot_image <- function(x_size, y_size) {
dta_points <- crossing(x = c(-x_size, x_size), y = c(-y_size, y_size))
dta_img <- data_frame(x = 0, y = 0, image = 'https://www.r-project.org/logo/Rlogo.png')
ggplot(NULL, aes(x, y)) +
geom_point(data = dta_points) +
geom_image(data = dta_img, aes(image = image), size = 1) +
ggtitle(paste0('x_size: ', x_size, ', y_size: ', y_size)) +
coord_fixed()
}
plot_image(x_size = 1, y_size = 1)
plot_image(x_size = 0.1, y_size = 1)
plot_image(x_size = 1, y_size = 0.1)