I am trying to fit the plot that is displayed over the background image. I cannot stretch the image too much because of the loss of sharpness. Therefore, I have to fit the plot over the background image which is much thinner than the plot. I do not know how to do it. Please see the attached plot:
Here is the sample R Code:
library(ggplot2)
library(readxl)
library(jpeg)
library(grid)
# find the ".jpg" image files and parse them to get the depth ranges for each image
setwd('~/R/Image_Example')
image_file <- "C1_9195-9197.jpg"
# read in the image file
img <- readJPEG(image_file)
g <- rasterGrob(img, interpolate = FALSE)
# read in the CT data
df_ct <- read_excel("CT_Doris25_short.xlsx", col_names = FALSE)
g_ct <- ggplot(data=df_ct) +
annotation_custom(g, xmin=min(df_ct$X1), xmax=max(df_ct$X1), ymin=-Inf, ymax=Inf) +
geom_path(aes_string(x=df_ct$X1, y=df_ct$X0), color='cyan') +
scale_y_reverse() +
theme(plot.margin = unit(c(0,0,0,0), "lines"))
g_ct
As you can see,
I am trying to adjust the xmin and xmax in annotation_custom. Is there a way where the plot shown in 'cyan' color can be fit perfectly over the 'width' of the background image? I do not mind if the graph is thinner and the X-axis is not shown. In fact, that is what I do when I assemble the plot with a number of other plots using gridExtra package.
I would like to display the starting depth 9195 at the top of the image shown, and ending depth 9197 at the bottom of the image. Then I do not need the Y axis. I know how to suppress the the display of X axis and Y axis labels. So that is not a problem. I turned them on for clarification. Can that be done programmatically?
As you can see that the ticks along the Y axis vary in steps of 0.5, i.e., 9195, 9195.5, 9196, ... and so on. I would like to make them go up (or down) in steps of 0.1 instead of 0.5. Also, I do not want to show the Y-axis labels, just ticks. The depth at the top of the image (9195) and the bottom (9197) is sufficient.
So it should look similar to the image shown below:
Please disregard the colorful plot to the left, that is a separate plot which I cannot get rid of, otherwise I cannot show the 'ticks'. It was done using MatLab. I am trying to replace the MatLab plot with an R plot. Matlab is using TIFF images which are much heavier but also much sharper. I am going with JPEG which is acceptable.
Thanks for your time.