2011-03-11 18 views
37

मैंने 3 मिलियन अंक के साथ साजिश बनाई और इसे पीएनजी के रूप में सहेजा। इसमें कुछ घंटे लग गए और मैं सभी बिंदुओं को दोबारा खींचने से बचना चाहता हूं।पृष्ठभूमि के रूप में एक पीएनजी के साथ साजिश कैसे करें?

enter image description here

मैं कथानक को एक नया एक पृष्ठभूमि के रूप में इस पीएनजी है कि कैसे बना सकता है?

+2

इसका कभी भी उपयोग नहीं किया गया, लेकिन पैकेज 'png' में आपके पास क्या हो सकता है: http://cran.r-project.org/web/packages/png/png.pdf – Chase

+1

कुछ टी जोड़ना अच्छा होगा अपने अंक के लिए ransparency, तो आप उनके वितरण बेहतर देख सकते हैं। एक घनत्व साजिश की तरह। – Rodrigo

+1

http://stackoverflow.com/a/42611002/15485 पर एक नज़र डालें –

उत्तर

77

इस प्रयास करें:

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

नीचे साजिश है।

enter image description here

15

जबकि @ bill_080 के जवाब आपके सवाल का सीधे जवाब, यह वास्तव में आप क्या चाहते है? यदि आप इस पर साजिश करना चाहते हैं, तो आपको अपने समन्वय प्रणाली को ध्यान से संरेखित करना होगा। उदाहरण देखें Houston Crime Map यह ggplot2 के साथ कैसे किया जा सकता है।

आपकी समस्या के लिए, मुझे लगता है कि यह एक आसान समाधान हो सकता है: बिनिंग, यानी 2 डी हिस्टोग्राम।

> 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 

enter image description here

hexbin जाली और ggplot2 के साथ सीधे काम करता है, लेकिन केंद्र डिब्बे के निर्देशांक [email protected] और [email protected] में हैं, इसलिए आप भी आधार ग्राफिक्स में परिणाम साजिश सकता है। डिब्बे की उच्च संख्या के साथ, आप अपने मूल कथानक की एक तेजी से संस्करण प्राप्त:

> system.time (plot ([email protected], [email protected], pch = 20, cex=0.4)) 
     User  System verstrichen 
     0.780  0.004  0.786 

enter image description here

लेकिन आप आसानी से रंग घनत्व कोडिंग हो सकता है:

> plot ([email protected], [email protected], pch = 20, cex=0.4, col = as.character (col)) 

> col <- cut ([email protected], 20) 
> levels (col) <- grey.colors (20, start=0.9, end = 0) 
> plot ([email protected], [email protected], pch = 20, cex=0.4, col = as.character (col)) 

enter image description here

संबंधित मुद्दे