How can i remove white lines around images when using image_montage in magick

137 Views Asked by At

I have created an image_montage using the magick package in R and i want to remove the white lines in between the images (the sample image is slightly cropped because of sensitive material)

image montage with white lines

the code I’ve used is:

twitter_image <- image_montage(imgs, tile = '4x2', geometry = "x500+0+0", bg = navy)

imgs is a list of images that are made from ggplot graphs

sample of graph code (all graphs follow the same code)


chart_ina = ggplot(chart_dataina,
                          aes(x=as.Date(los_date))) +
    geom_line(aes(y=eas), size=1,color="white") +
    xlab("") + ylab("")+
    theme(text = element_text(size = 16), axis.title.y = element_text(angle = 0), plot.margin=unit (c (1,1,1,1), 'cm'))+
    scale_y_continuous(limits = c(22,32), breaks = c(22,32))+
    scale_x_date(breaks = c(xfirst, xlast), labels = c(xfirst_label,xlast_label),
                 minor_breaks = NULL) +
    theme(
      panel.grid = element_blank(),
      panel.border = element_blank(),
      panel.background = element_rect(fill = navy),
      plot.background = element_rect(fill = navy),
      axis.line.x = element_line(colour = 'white', size=0.5, linetype='solid'),
      axis.line.y = element_blank()) +
    theme(plot.title = element_text(size = 20, color="white", hjust=0.5),
          axis.text=(element_text(size = 12, colour = "white")),
          axis.title.y = element_text(angle = 0),
          plot.margin=unit(c(1,1,1,1),'cm'))
 
1

There are 1 best solutions below

0
Karl Edwards On

It looks like each image has a white border.

To remove this, and make the border the same color as the plot, add color to panel.background and plot.background in the plot definitions, as follows:

 panel.background = element_rect(fill = navy, color = navy),
 plot.background = element_rect(fill = navy , color = navy)

Reference: Change background color of ggplot2 plot in R