titles tag img images attribute and r data-visualization large-data

tag - Cómo trazar con un png como fondo?



meta alt tag (2)

Esta pregunta ya tiene una respuesta aquí:

Hice una trama con 3 millones de puntos y la guardé como PNG. Tomó algunas horas y me gustaría evitar volver a dibujar todos los puntos.

¿Cómo puedo generar una nueva gráfica que tenga este PNG como fondo?


Mientras que la respuesta de @ bill_080 responde directamente a su pregunta, ¿es esto realmente lo que quiere? Si quiere trazar esto, deberá alinear cuidadosamente sus sistemas de coordenadas. Ver, por ejemplo, Houston Crime Map cómo se puede hacer esto con ggplot2.

Para su problema, me parece que puede haber una solución más fácil: binning, es decir, cedar 2d histogramas.

> df <- data.frame (x = rnorm (1e6), y = rnorm (1e6)) > system.time (plot (df)) User System verstrichen 54.468 0.044 54.658 > library (hexbin) > system.time (binned <- hexbin (df, xbins=200)) User System verstrichen 0.252 0.012 0.266 > system.time (plot (binned)) User System verstrichen 0.704 0.040 0.784

hexbin funciona directamente con celosía y ggplot2, pero las coordenadas centrales de los contenedores están en binned@xcm y binned@ycm , por lo que también puedes trazar el resultado en gráficos base. Con un gran número de contenedores, obtienes una versión rápida de tu trama original:

> system.time (plot (binned@xcm, binned@ycm, pch = 20, cex=0.4)) User System verstrichen 0.780 0.004 0.786

pero puede tener fácilmente los colores que codifican la densidad:

> plot (binned@xcm, binned@ycm, pch = 20, cex=0.4, col = as.character (col)) > col <- cut (binned@count, 20) > levels (col) <- grey.colors (20, start=0.9, end = 0) > plot (binned@xcm, binned@ycm, pch = 20, cex=0.4, col = as.character (col))


Prueba esto:

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")

A continuación está la trama.