2012-10-19 14 views
12

पर रीग्रेशन लाइन के साथ xyplot प्लॉटिंग मैंने जाली पैकेज लोड किया है। तब मैं चलाएँ:जाली ग्राफिक्स

> xyplot(yyy ~ xxx | zzz, panel = function(x,y) { panel.lmline(x,y)} 

इस साजिश के पैनलों, प्रतिगमन लाइन दिखा पैदा करता है, xyplots बिना। मैं पूरी तरह से समझने के बिना पैनल.ललाइन कर रहा हूं कि यह कैसे किया जाता है। मुझे पता है कि एक डेटा तर्क है, डेटा क्या है, यह जानकर कि मेरे पास 3 चर xxx, yyy, zzz है?

उत्तर

22

तुम सब वास्तव में जरूरत है:

xyplot(yyy ~ xxx | zzz, type = c("p","r")) 

जहां type तर्क ?panel.xyplot

में प्रलेखित है मैं यह सब बोली नहीं होगा लेकिन

type: character vector consisting of one or more of the following: 
     ‘"p"’, ‘"l"’, ‘"h"’, ‘"b"’, ‘"o"’, ‘"s"’, ‘"S"’, ‘"r"’, 
     ‘"a"’, ‘"g"’, ‘"smooth"’, and ‘"spline"’. If ‘type’ has more 
     than one element, an attempt is made to combine the effect of 
     each of the components. 

     The behaviour if any of the first six are included in ‘type’ 
     is similar to the effect of ‘type’ in ‘plot’ (type ‘"b"’ is 
     actually the same as ‘"o"’). ‘"r"’ adds a linear regression 
     line (same as ‘panel.lmline’, except for default graphical 
     parameters). ‘"smooth"’ adds a loess fit (same as 
     ‘panel.loess’). ‘"spline"’ adds a cubic smoothing spline fit 
     (same as ‘panel.spline’). ‘"g"’ adds a reference grid using 
     ‘panel.grid’ in the background (but using the ‘grid’ argument 
     is now the preferred way to do so). ‘"a"’ has the effect of 
     calling ‘panel.average’, which can be useful for creating 
     interaction plots. The effect of several of these 
     specifications depend on the value of ‘horizontal’. 

आप कर सकते हैं, जैसा कि मैंने पता चला ऊपर, type एक चरित्र वेक्टर पास करके श्रृंखला में इन्हें जोड़ें। अनिवार्य रूप से, आपके कोड ने type = "r" के समान परिणाम दिए, यानी केवल रीग्रेशन लाइन खींची गई थी।

panelxyplot का तर्क, और सामान्य रूप से लैटिस साजिश कार्य, बेहद शक्तिशाली है लेकिन हमेशा जटिल चीजों के लिए आवश्यक नहीं है। असल में आपको panel एक फ़ंक्शन पारित करने की आवश्यकता है जो साजिश के प्रत्येक पैनल पर चीजें खींच लेगा। जो भी आप चाहते थे उसे करने के लिए अपने कोड को संशोधित करने के लिए, हमें panel.xyplot() पर भी कॉल जोड़ने की आवश्यकता है। उदा .:

xyplot(yyy ~ xxx | zzz, 
     panel = function(x, y, ...) { 
       panel.xyplot(x, y, ...) 
       panel.lmline(x, y, ...) 
       }) 

यह भी उस स्थिति में आप अपने गुमनाम कार्यों में एक तर्क के रूप ... जरूरत है (जैसा कि ऊपर दिखाया गया है) ... के माध्यम से अलग-अलग पैनल कार्यों पर अन्य सभी तर्क पारित करने के लिए बहुत उपयोगी है। वास्तव में, आप शायद के रूप में है कि पैनल समारोह हिस्सा लिख ​​सकते हैं:

xyplot(yyy ~ xxx | zzz, 
     panel = function(...) { 
       panel.xyplot(...) 
       panel.lmline(...) 
       }) 

लेकिन मैं आमतौर पर x और y तर्क सिर्फ स्पष्ट किए जाने की जोड़ें।

+0

गेविन आपके उत्तर के लिए धन्यवाद। – Selvam

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