Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to plot with a png as background? [duplicate]

I made a plot with a 3 million points and saved it as PNG. It took a few hours and I would like to avoid re-drawing all the points.

enter image description here

How can I generate a new plot that has this PNG as a background?

like image 205
Aleksandr Levchuk Avatar asked Mar 11 '11 17:03

Aleksandr Levchuk


People also ask

How do you change the background color of a plot?

set_facecolor() method is used to change the inner background color of the plot. figure(facecolor='color') method is used to change the outer background color of the plot.

How do I make a background transparent in R?

There is no option in Format pane to make the R visual background to be transparent. Only small part (around the R visual) can be transparent as below. But we should be able to set bg="transparent" to make it to be transparent like below. Could you please share your R scripts written in the R script editor?


1 Answers

Try this:

library(png)  #Replace the directory and file information with your info ima <- readPNG("C:\\Documents and Settings\\Bill\\Data\\R\\Data\\Images\\sun.png")  #Set up the plot area plot(1:2, type='n', main="Plotting Over an Image", xlab="x", ylab="y")  #Get the plot information so the image will fill the plot box, and draw it lim <- par() rasterImage(ima, lim$usr[1], lim$usr[3], lim$usr[2], lim$usr[4]) grid() lines(c(1, 1.2, 1.4, 1.6, 1.8, 2.0), c(1, 1.3, 1.7, 1.6, 1.7, 1.0), type="b", lwd=5, col="white") 

Below is the plot.

enter image description here

like image 130
bill_080 Avatar answered Nov 02 '22 13:11

bill_080