[R] Overlay of barchart and xyplot

Chen, Huapeng FOR:EX Huapeng.Chen at gov.bc.ca
Fri Jun 4 20:49:19 CEST 2010


Hi Felix,

Thanks for your help and advice. The following code is close to what I want but still have problems of failure to custom lines and add a key in any way. Par.settings with the final plot seems not working somehow except pch and lty but they overwrite par.setting with barchart. I also attached data I used by using "dput". I appreciate your further helps.

Thanks,

Huapeng


######### code #############################################################
NTLST_Dispersal_VAR_00_08$Year <- factor(NTLST_Dispersal_VAR_00_08$Year, levels = c("1999","2000","2001","2002","2003","2004","2005","2006","2007"), ordered = TRUE)

dispersal<-barchart(NTLST_Dispersal_VAR_00_08$LDP_PER*100 +            
                     NTLST_Dispersal_VAR_00_08$SPP_PER*100 +                                    
                     NTLST_Dispersal_VAR_00_08$SPG_PER*100 ~                            
                     NTLST_Dispersal_VAR_00_08$Year | NTLST_Dispersal_VAR_00_08$District,       
                     data=NTLST_Dispersal_VAR_00_08,                                    
                     horizontal=FALSE,                                                  
                     stack=TRUE,                                                        
                     layout=c(5,5),                                                     
                     xlab="Year",                                                       
                     ylab="%",                                                          
                     strip = strip.custom( bg="light gray"),                             
                     par.settings = simpleTheme(col = c("dark gray", "light gray", "white")),
                     #key=list(space="right",size=10, 
                     # rectangles=list(size=1.7, border="black", col = c("white", "dark gray", "black")),
                      #lines=list(pch=c(16,17),lty=c(1,2),col="black",type="b"),
                     # text=list(text=c("SPG","SPP","LDP")))                             
   
                     #auto.key=TRUE                                                     
                     )                                                                  
                                                                            
                                                                            
                                                                            
xyplot(sqrt(NTLST_Dispersal_VAR_00_08$Infestation_NUM) +             
             NTLST_Dispersal_VAR_00_08$AI  ~  NTLST_Dispersal_VAR_00_08$Year | NTLST_Dispersal_VAR_00_08$District,         
             data=NTLST_Dispersal_VAR_00_08,                                            
             layout=c(5,5),                                                             
             type="b",                                                                  
             ylab="Square roots of number of infested cells/Landscape aggregation index",
             #par.settings = simpleTheme(col = c("black", "black"), pch=c(16,17)), 
             #key=list(space="right",size=10, 
                      #rectangles=list(size=1.7, border="black", col = c("white", "dark gray", "black")),
             #         lines=list(pch=c(16,17),lty=c(1,2),col="black",type="b"),
             #         text=list(text=c("t4","t5")))                             
      
             )                                                                          
                                                                            
 doubleYScale(dispersal, vars, use.style=FALSE, add.ylab2 = TRUE
             )                                                                          
                                                                            
 update(trellis.last.object(),                                              
 par.settings = simpleTheme(fill = c("white", "dark gray", "black"), border="black",col.line="black",
                            col.points="black",pch=c(16,17),lty=c(1,1,1,2,1)))

######################################################################################################

################ DATA #############################################################################
> dput(NTLST_Dispersal_VAR_00_08)
structure(list(District = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 
5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 
8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 10L, 10L, 10L, 10L, 
10L, 10L, 10L, 10L, 10L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 
11L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 13L, 13L, 13L, 
13L, 13L, 13L, 13L, 13L, 13L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 
14L, 14L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 16L, 16L, 
16L, 16L, 16L, 16L, 16L, 16L, 16L, 17L, 17L, 17L, 17L, 17L, 17L, 
17L, 17L, 17L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 19L, 
19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 20L, 20L, 20L, 20L, 20L, 
20L, 20L, 20L, 20L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 
22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 24L, 24L, 24L, 24L, 
24L, 24L, 24L, 24L, 24L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 
23L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L), .Label = c("DAB", 
"DCC", "DCH", "DCK", "DCO", "DCS", "DHW", "DIC", "DJA", "DKA", 
"DKL", "DKM", "DMH", "DMK", "DND", "DOS", "DPC", "DPG", "DQU", 
"DRM", "DSC", "DSQ", "DSS_N", "DSS_S", "DVA"), class = "factor"), 
    Year = c(1999L, 2000L, 2001L, 2002L, 2003L, 2004L, 2005L, 
    2006L, 2007L, 1999L, 2000L, 2001L, 2002L, 2003L, 2004L, 2005L, 
    2006L, 2007L, 1999L, 2000L, 2001L, 2002L, 2003L, 2004L, 2005L, 
    2006L, 2007L, 1999L, 2000L, 2001L, 2002L, 2003L, 2004L, 2005L, 
    2006L, 2007L, 1999L, 2000L, 2001L, 2002L, 2003L, 2004L, 2005L, 
    2006L, 2007L, 1999L, 2000L, 2001L, 2002L, 2003L, 2004L, 2005L, 
    2006L, 2007L, 1999L, 2000L, 2001L, 2002L, 2003L, 2004L, 2005L, 
    2006L, 2007L, 1999L, 2000L, 2001L, 2002L, 2003L, 2004L, 2005L, 
    2006L, 2007L, 1999L, 2000L, 2001L, 2002L, 2003L, 2004L, 2005L, 
    2006L, 2007L, 1999L, 2000L, 2001L, 2002L, 2003L, 2004L, 2005L, 
    2006L, 2007L, 1999L, 2000L, 2001L, 2002L, 2003L, 2004L, 2005L, 
    2006L, 2007L, 1999L, 2000L, 2001L, 2002L, 2003L, 2004L, 2005L, 
    2006L, 2007L, 1999L, 2000L, 2001L, 2002L, 2003L, 2004L, 2005L, 
    2006L, 2007L, 1999L, 2000L, 2001L, 2002L, 2003L, 2004L, 2005L, 
    2006L, 2007L, 1999L, 2000L, 2001L, 2002L, 2003L, 2004L, 2005L, 
    2006L, 2007L, 1999L, 2000L, 2001L, 2002L, 2003L, 2004L, 2005L, 
    2006L, 2007L, 1999L, 2000L, 2001L, 2002L, 2003L, 2004L, 2005L, 
    2006L, 2007L, 1999L, 2000L, 2001L, 2002L, 2003L, 2004L, 2005L, 
    2006L, 2007L, 1999L, 2000L, 2001L, 2002L, 2003L, 2004L, 2005L, 
    2006L, 2007L, 1999L, 2000L, 2001L, 2002L, 2003L, 2004L, 2005L, 
    2006L, 2007L, 1999L, 2000L, 2001L, 2002L, 2003L, 2004L, 2005L, 
    2006L, 2007L, 1999L, 2000L, 2001L, 2002L, 2003L, 2004L, 2005L, 
    2006L, 2007L, 1999L, 2000L, 2001L, 2002L, 2003L, 2004L, 2005L, 
    2006L, 2007L, 1999L, 2000L, 2001L, 2002L, 2003L, 2004L, 2005L, 
    2006L, 2007L, 1999L, 2000L, 2001L, 2002L, 2003L, 2004L, 2005L, 
    2006L, 2007L), SPG_PER = c(0.446808511, 0.480769231, 0.366141732, 
    0.663366337, 0.553278689, 0.799204771, 0.824295011, 0.794520548, 
    0.77972028, 0.844036697, 0.7731569, 0.905714286, 0.799256506, 
    0.896703297, 0.887254902, 0.923728814, 0.941935484, 0.890909091, 
    0.691176471, 0.245901639, 0.525316456, 0.326599327, 0.797342193, 
    0.720430108, 0.773480663, 0.943319838, 0.961038961, 0.611111111, 
    0.48, 0.511111111, 0.6875, 0.649122807, 1, 0.541353383, 0.685314685, 
    0.9, 0.553846154, 0.491525424, 0.604938272, 0.636363636, 
    0.644067797, 0.660606061, 0.728723404, 0.807017544, 0.833333333, 
    0.677570093, 0.594936709, 0.758169935, 0.792035398, 0.690026954, 
    0.718808194, 0.863987635, 0.8815427, 0.950746269, 0.261904762, 
    0.556701031, 0.606382979, 0.6, 0.494565217, 0.609929078, 
    0.871060172, 0.896296296, 0.907563025, 0.542857143, 0.848101266, 
    0.744444444, 0.844155844, 0.653846154, 0.755319149, 0.476190476, 
    0.836363636, 0.764705882, 0.880143113, 0.915492958, 0.723776224, 
    0.774390244, 0.8, 0.818615752, 0.890625, 0.93129771, 0.808823529, 
    0.701149425, 0.672340426, 0.773722628, 0.861423221, 0.796407186, 
    0.866197183, 0.949554896, 0.937704918, 0.937062937, 0.4375, 
    0.269230769, 0.476190476, 0.518072289, 0.524444444, 0.626198083, 
    0.820189274, 0.845132743, 0.836012862, 0.1875, 0, 0, 0, 0, 
    0, 0, 0, 0.078431373, 0.806451613, 0.627118644, 0.768292683, 
    0.66751269, 0.967948718, 0.97979798, 0.986111111, 0.975609756, 
    1, 0.291925466, 0.416666667, 0.086956522, 0.060344828, 0.694805195, 
    0.616541353, 0.79245283, 0.411894273, 0.805929919, 0.653030303, 
    0.882352941, 0.787056367, 0.827763496, 0.703448276, 0.86453202, 
    0.93030303, 0.907216495, 0.9390681, 0.465277778, 0.402730375, 
    0.706666667, 0.536036036, 0.596273292, 0.655660377, 0.754990926, 
    0.815485997, 0.846889952, 0, 0, 0, 0, 0.011494253, 0.578512397, 
    0.554621849, 0.189655172, 0.62247191, 0.646907216, 0.575289575, 
    0.698979592, 0.608961303, 0.843629344, 0.881889764, 0.85, 
    0.825, 0.877192982, 0.970454545, 0.88255814, 0.982068966, 
    0.961267606, 0.956521739, 0.930555556, 1, 0.901408451, 0.905660377, 
    0.598360656, 0.289855072, 0.517985612, 0.543568465, 0.581932773, 
    0.628881988, 0.83902439, 0.846153846, 0.85089141, 0, 0, 0, 
    0, 0, 0, 0, 0, 0, 0.571428571, 0.848484848, 0.756756757, 
    0.793103448, 0.683544304, 0.5, 0.627906977, 0.887850467, 
    0.948717949, 0.333333333, 0.5, 0.256410256, 0.240740741, 
    0.418918919, 0.593495935, 0.695652174, 0.658823529, 0.642857143, 
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0.836956522, 0.854609929, 0.908235294, 
    1, 0.974576271, 0.942857143, 0.978021978, 0.984126984, 0.9
    ), SPP_PER = c(0.205673759, 0.192307692, 0.212598425, 0.222772277, 
    0.178278689, 0.115308151, 0.106290672, 0.131506849, 0.148601399, 
    0.105504587, 0.096408318, 0.065714286, 0.066914498, 0.065934066, 
    0.068627451, 0.06779661, 0.04516129, 0.072727273, 0.161764706, 
    0.151639344, 0.189873418, 0.111111111, 0.102990033, 0.134408602, 
    0.066298343, 0.032388664, 0.019480519, 0.055555556, 0.04, 
    0.111111111, 0.09375, 0.052631579, 0, 0.157894737, 0.111888112, 
    0.075, 0.015384615, 0.186440678, 0.160493827, 0.181818182, 
    0.186440678, 0.109090909, 0.122340426, 0.096491228, 0.083333333, 
    0.154205607, 0.180379747, 0.137254902, 0.092920354, 0.137466307, 
    0.137802607, 0.094281298, 0.067493113, 0.046268657, 0.19047619, 
    0.175257732, 0.170212766, 0.1, 0.125, 0.092198582, 0.068767908, 
    0.061728395, 0.079831933, 0.180952381, 0.088607595, 0.077777778, 
    0.077922078, 0.051282051, 0.14893617, 0.111111111, 0.090909091, 
    0.088235294, 0.096601073, 0.046948357, 0.129370629, 0.12195122, 
    0.093333333, 0.057279236, 0.07421875, 0.043256997, 0.098039216, 
    0.206896552, 0.153191489, 0.142335766, 0.101123596, 0.095808383, 
    0.08685446, 0.050445104, 0.059016393, 0.055944056, 0.125, 
    0.211538462, 0.277777778, 0.21686747, 0.235555556, 0.162939297, 
    0.129337539, 0.132743363, 0.102893891, 0.0625, 0, 0, 0, 0, 
    0, 0, 0, 0.019607843, 0.088709677, 0.189265537, 0.146341463, 
    0.162436548, 0.019230769, 0, 0.013888889, 0.024390244, 0, 
    0.149068323, 0, 0.086956522, 0.081896552, 0.214285714, 0.157894737, 
    0.090566038, 0.057268722, 0.09703504, 0.142424242, 0.068627451, 
    0.11691023, 0.12596401, 0.172413793, 0.061576355, 0.039393939, 
    0.059278351, 0.046594982, 0.173611111, 0.177474403, 0.16, 
    0.126126126, 0.158385093, 0.141509434, 0.105263158, 0.10708402, 
    0.082934609, 0, 0, 0, 0, 0.011494253, 0.132231405, 0.142857143, 
    0.012931034, 0.134831461, 0.131443299, 0.223938224, 0.140306122, 
    0.130346232, 0.081081081, 0.078740157, 0.095, 0.1125, 0.105263158, 
    0.020454545, 0.061627907, 0.012413793, 0.021126761, 0.040133779, 
    0.055555556, 0, 0.084507042, 0.056603774, 0.090163934, 0.154589372, 
    0.208633094, 0.149377593, 0.165966387, 0.163043478, 0.105691057, 
    0.112570356, 0.079416532, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.321428571, 
    0.121212121, 0.108108108, 0.103448276, 0.17721519, 0.5, 0.139534884, 
    0.093457944, 0.051282051, 0.1, 0.166666667, 0.179487179, 
    0.259259259, 0.148648649, 0.25203252, 0.173913043, 0.094117647, 
    0.178571429, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.099637681, 0.109929078, 
    0.054117647, 0, 0.025423729, 0.047619048, 0.021978022, 0.015873016, 
    0.1), LDP_PER = c(0.34751773, 0.326923077, 0.421259843, 0.113861386, 
    0.268442623, 0.085487078, 0.069414317, 0.073972603, 0.071678322, 
    0.050458716, 0.130434783, 0.028571429, 0.133828996, 0.037362637, 
    0.044117647, 0.008474576, 0.012903226, 0.036363636, 0.147058824, 
    0.602459016, 0.284810127, 0.562289562, 0.099667774, 0.14516129, 
    0.160220994, 0.024291498, 0.019480519, 0.333333333, 0.48, 
    0.377777778, 0.21875, 0.298245614, 0, 0.30075188, 0.202797203, 
    0.025, 0.430769231, 0.322033898, 0.234567901, 0.181818182, 
    0.169491525, 0.23030303, 0.14893617, 0.096491228, 0.083333333, 
    0.168224299, 0.224683544, 0.104575163, 0.115044248, 0.172506739, 
    0.143389199, 0.041731066, 0.050964187, 0.002985075, 0.547619048, 
    0.268041237, 0.223404255, 0.3, 0.380434783, 0.29787234, 0.06017192, 
    0.041975309, 0.012605042, 0.276190476, 0.063291139, 0.177777778, 
    0.077922078, 0.294871795, 0.095744681, 0.412698413, 0.072727273, 
    0.147058824, 0.023255814, 0.037558685, 0.146853147, 0.103658537, 
    0.106666667, 0.124105012, 0.03515625, 0.025445293, 0.093137255, 
    0.091954023, 0.174468085, 0.083941606, 0.037453184, 0.107784431, 
    0.046948357, 0, 0.003278689, 0.006993007, 0.4375, 0.519230769, 
    0.246031746, 0.265060241, 0.24, 0.21086262, 0.050473186, 
    0.022123894, 0.061093248, 0.75, 0, 1, 1, 0, 1, 0, 1, 0.901960784, 
    0.10483871, 0.183615819, 0.085365854, 0.170050761, 0.012820513, 
    0.02020202, 0, 0, 0, 0.559006211, 0.583333333, 0.826086957, 
    0.857758621, 0.090909091, 0.22556391, 0.116981132, 0.530837004, 
    0.09703504, 0.204545455, 0.049019608, 0.096033403, 0.046272494, 
    0.124137931, 0.073891626, 0.03030303, 0.033505155, 0.014336918, 
    0.361111111, 0.419795222, 0.133333333, 0.337837838, 0.245341615, 
    0.202830189, 0.139745917, 0.077429984, 0.070175439, 1, 1, 
    1, 1, 0.977011494, 0.289256198, 0.302521008, 0.797413793, 
    0.242696629, 0.221649485, 0.200772201, 0.160714286, 0.260692464, 
    0.075289575, 0.039370079, 0.055, 0.0625, 0.01754386, 0.009090909, 
    0.055813953, 0.005517241, 0.017605634, 0.003344482, 0.013888889, 
    0, 0.014084507, 0.037735849, 0.31147541, 0.555555556, 0.273381295, 
    0.307053942, 0.25210084, 0.208074534, 0.055284553, 0.041275797, 
    0.069692058, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0.107142857, 0.03030303, 
    0.135135135, 0.103448276, 0.139240506, 0, 0.23255814, 0.018691589, 
    0, 0.566666667, 0.333333333, 0.564102564, 0.5, 0.432432432, 
    0.154471545, 0.130434783, 0.247058824, 0.178571429, 0, 1, 
    1, 0, 0, 0, 0, 0, 0, 0.063405797, 0.035460993, 0.037647059, 
    0, 0, 0.00952381, 0, 0, 0), SPP_LDP_PER = c(0.553191489, 
    0.519230769, 0.633858268, 0.336633663, 0.446721311, 0.200795229, 
    0.175704989, 0.205479452, 0.22027972, 0.155963303, 0.2268431, 
    0.094285714, 0.200743494, 0.103296703, 0.112745098, 0.076271186, 
    0.058064516, 0.109090909, 0.308823529, 0.754098361, 0.474683544, 
    0.673400673, 0.202657807, 0.279569892, 0.226519337, 0.056680162, 
    0.038961039, 0.388888889, 0.52, 0.488888889, 0.3125, 0.350877193, 
    0, 0.458646617, 0.314685315, 0.1, 0.446153846, 0.508474576, 
    0.395061728, 0.363636364, 0.355932203, 0.339393939, 0.271276596, 
    0.192982456, 0.166666667, 0.322429907, 0.405063291, 0.241830065, 
    0.207964602, 0.309973046, 0.281191806, 0.136012365, 0.1184573, 
    0.049253731, 0.738095238, 0.443298969, 0.393617021, 0.4, 
    0.505434783, 0.390070922, 0.128939828, 0.103703704, 0.092436975, 
    0.457142857, 0.151898734, 0.255555556, 0.155844156, 0.346153846, 
    0.244680851, 0.523809524, 0.163636364, 0.235294118, 0.119856887, 
    0.084507042, 0.276223776, 0.225609756, 0.2, 0.181384248, 
    0.109375, 0.06870229, 0.191176471, 0.298850575, 0.327659574, 
    0.226277372, 0.138576779, 0.203592814, 0.133802817, 0.050445104, 
    0.062295082, 0.062937063, 0.5625, 0.730769231, 0.523809524, 
    0.481927711, 0.475555556, 0.373801917, 0.179810726, 0.154867257, 
    0.163987138, 0.8125, 0, 1, 1, 0, 1, 0, 1, 0.921568627, 0.193548387, 
    0.372881356, 0.231707317, 0.33248731, 0.032051282, 0.02020202, 
    0.013888889, 0.024390244, 0, 0.708074534, 0.583333333, 0.913043478, 
    0.939655172, 0.305194805, 0.383458647, 0.20754717, 0.588105727, 
    0.194070081, 0.346969697, 0.117647059, 0.212943633, 0.172236504, 
    0.296551724, 0.13546798, 0.06969697, 0.092783505, 0.0609319, 
    0.534722222, 0.597269625, 0.293333333, 0.463963964, 0.403726708, 
    0.344339623, 0.245009074, 0.184514003, 0.153110048, 1, 1, 
    1, 1, 0.988505747, 0.421487603, 0.445378151, 0.810344828, 
    0.37752809, 0.353092784, 0.424710425, 0.301020408, 0.391038697, 
    0.156370656, 0.118110236, 0.15, 0.175, 0.122807018, 0.029545455, 
    0.11744186, 0.017931034, 0.038732394, 0.043478261, 0.069444444, 
    0, 0.098591549, 0.094339623, 0.401639344, 0.710144928, 0.482014388, 
    0.456431535, 0.418067227, 0.371118012, 0.16097561, 0.153846154, 
    0.14910859, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0.428571429, 0.151515152, 
    0.243243243, 0.206896552, 0.316455696, 0.5, 0.372093023, 
    0.112149533, 0.051282051, 0.666666667, 0.5, 0.743589744, 
    0.759259259, 0.581081081, 0.406504065, 0.304347826, 0.341176471, 
    0.357142857, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0.163043478, 0.145390071, 
    0.091764706, 0, 0.025423729, 0.057142857, 0.021978022, 0.015873016, 
    0.1), Infestation_NUM = c(461L, 332L, 663L, 791L, 2138L, 
    2921L, 2783L, 2210L, 2466L, 2077L, 4294L, 4302L, 6095L, 7919L, 
    8516L, 7759L, 6637L, 4288L, 204L, 1099L, 1350L, 9332L, 11416L, 
    13120L, 13726L, 14393L, 13729L, 75L, 109L, 185L, 202L, 332L, 
    315L, 603L, 912L, 639L, 401L, 253L, 300L, 312L, 420L, 1105L, 
    987L, 654L, 726L, 898L, 1171L, 1266L, 1044L, 1919L, 3952L, 
    5333L, 7164L, 7914L, 219L, 321L, 433L, 325L, 856L, 2470L, 
    3054L, 3590L, 2830L, 704L, 1294L, 1673L, 1604L, 1517L, 1675L, 
    1374L, 1122L, 616L, 2971L, 1887L, 2032L, 3282L, 5850L, 7699L, 
    7539L, 8254L, 5261L, 664L, 914L, 1285L, 1602L, 3279L, 4821L, 
    5073L, 4508L, 3303L, 103L, 210L, 306L, 279L, 731L, 1470L, 
    1584L, 1541L, 1487L, 100L, 3L, 11L, 2L, 0L, 4L, 0L, 7L, 198L, 
    782L, 1248L, 1223L, 2821L, 6995L, 7524L, 7436L, 6645L, 5398L, 
    774L, 52L, 135L, 1045L, 781L, 2252L, 3312L, 5273L, 6230L, 
    5471L, 4960L, 5549L, 5608L, 8666L, 12418L, 11662L, 11492L, 
    8035L, 446L, 805L, 634L, 873L, 1668L, 2662L, 3544L, 4671L, 
    4677L, 7L, 5L, 12L, 2L, 471L, 563L, 930L, 8600L, 6168L, 2066L, 
    1558L, 2495L, 4785L, 7582L, 8725L, 8139L, 6407L, 1833L, 4284L, 
    6612L, 7869L, 10488L, 11055L, 10510L, 8971L, 7300L, 4607L, 
    550L, 604L, 870L, 884L, 1789L, 3827L, 3270L, 2862L, 2939L, 
    0L, 0L, 0L, 0L, 0L, 0L, 0L, 5L, 2L, 115L, 134L, 179L, 191L, 
    315L, 155L, 542L, 561L, 307L, 296L, 104L, 82L, 127L, 252L, 
    681L, 330L, 620L, 1254L, 0L, 15L, 5L, 0L, 0L, 0L, 0L, 0L, 
    0L, 3934L, 3436L, 7218L, 7205L, 7581L, 7512L, 6804L, 5702L, 
    1503L), AI = c(48.9143, 37.3591, 37.3418, 41.7671, 54.333, 
    62.5666, 57.9458, 50.0829, 54.0918, 57.9, 75.5286, 74.709, 
    80.5838, 85.7303, 84.7028, 79.4637, 74.5994, 68.593, 38.2682, 
    55.3403, 52.3413, 88.5776, 93.0988, 94.1959, 93.0554, 92.2483, 
    90.2417, 64.9573, 60.2273, 56.1514, 65.8192, 61.6667, 67.156, 
    57.967, 59.3861, 55.8722, 65.1351, 43.5345, 46.5116, 48.2935, 
    48.1576, 63.7882, 56.3858, 54.4507, 62.6462, 52.0047, 48.5702, 
    49.8552, 45.3751, 54.9085, 66.3531, 71.5646, 75.7838, 76.9409, 
    37.2549, 45.8609, 58.3942, 46.8333, 54.397, 66.6243, 69.3746, 
    72.231, 66.9102, 68.6601, 86.3265, 87.5508, 85.0412, 79.1681, 
    78.304, 72.2288, 74.153, 74.0367, 60.2477, 65.7844, 63.723, 
    71.4947, 82.1387, 85.6676, 84.8122, 85.7152, 76.1957, 44.5783, 
    49.537, 55.4825, 60.6514, 73.0341, 80.719, 77.7062, 73.2482, 
    67.459, 38.674, 26.4935, 35.1687, 39.5303, 48.4604, 56.3481, 
    55.585, 55.2397, 58.2721, 62.7778, 0, 26.6667, 100, 0, 100, 
    0, 25, 47.2222, 43.6735, 48.3008, 52.2956, 68.8164, 94.044, 
    94.1802, 92.3288, 85.6805, 75.0219, 56.0565, 60.6742, 61.8257, 
    30.8505, 45.1211, 70.6888, 78.585, 74.0106, 80.155, 66.5264, 
    72.9658, 75.9388, 77.8278, 81.5686, 87.0732, 84.7279, 82.8008, 
    78.3983, 40.1009, 40.5114, 46.9974, 51.1307, 60.0195, 63.3554, 
    64.9501, 67.9142, 68.2716, 50, 20, 23.5294, 0, 57.6837, 57.5139, 
    61.8121, 81.8176, 76.1466, 62.9997, 52.5908, 67.905, 72.6611, 
    79.6883, 80.9021, 77.1513, 71.1271, 43.9323, 60.2221, 72.3244, 
    80.8686, 90.4216, 90.8316, 88.0082, 82.2638, 76.9269, 74.1128, 
    50.8118, 34.8958, 42.6269, 42.3888, 52.078, 60.2379, 53.6734, 
    52.1366, 58.114, 0, 0, 0, 0, 0, 0, 0, 40, 0, 53.3981, 53.3058, 
    58.006, 54.2373, 50, 34.4086, 52.8724, 54.8204, 42.3698, 
    45.709, 48.2558, 25.3623, 35.7466, 42.5629, 57.0268, 43.0088, 
    58.6108, 69.0699, 0, 9.0909, 40, 0, 0, 0, 0, 0, 0, 71.4188, 
    64.0399, 87.8145, 88.5683, 91.1567, 51.1308, 84.2769, 76.9757, 
    49.8218)), .Names = c("District", "Year", "SPG_PER", "SPP_PER", 
"LDP_PER", "SPP_LDP_PER", "Infestation_NUM", "AI"), class = "data.frame", row.names = c(NA, 
-225L))

###############################################################################################



-----Original Message-----
From: foolish.android at gmail.com [mailto:foolish.android at gmail.com] On Behalf Of Felix Andrews
Sent: Thursday, June 3, 2010 7:10 PM
To: Chen, Huapeng FOR:EX
Cc: r-help at r-project.org
Subject: Re: [R] Overlay of barchart and xyplot

Hi Huapeng,

Firstly, it is worth noting that it is often not recommended to
overlay series with different scales, so you should think about other
ways to present your data.

Secondly, when posting here it is much more helpful to provide the
data in a form that can be copied-and-pasted into R: so rather than
print(mydata), please use dput(mydata).

Regarding the doubleYScale() function from the latticeExtra package,
since you are overlaying grouped plots you should give use.style =
FALSE. Then specify an appropriate par.settings list to the final
plot, which might be
par.settings = simpleTheme(fill = c("dark gray", "light gray",
"white"), col = "black", pch=c(16,17), lty=c(1,2))
I haven't tested this, but I can if you send me your data in a dput() form.

Regarding a composite key, you could construct it using the general
'key' argument described in ?xyplot or if you want two keys in
different positions that would also be possible.

The doubleYScale() function was not really designed for handling such
complex plots... and again, I would encourage you to think about
simpler ways to present your data.

Hope that helps
-Felix


On 4 June 2010 01:48, Chen, Huapeng FOR:EX <Huapeng.Chen at gov.bc.ca> wrote:
>
> Hello,
>
> I am new to R. I am trying to use “DoubleYScale” to overlay one barchart with a xyplot with two lines. I have two problems. One is that I could not figure out how to custom line (point and line) with “par.settings” and seems to me that whatever “par.settings” I used to custom the barchart was also applied to the xyplot (lines) and I don’t know how to apply par.setting separately to each barchart and xyplot for  my customization.
>
> The other problem is how to add a key for both barchart and xyplot in a meaningful way.
>
> I attached a piece of R code below I have been struggling to get this to work. Your kind help and advice are greatly appreciated.
>
> Thanks,
>
> Huapeng
>
> ###############################################################################################################################################
> dispersal<-barchart(NTLST_Dispersal_VAR_00_08$LDP_PER*100 + NTLST_Dispersal_VAR_00_08$SPP_PER*100 +
>         NTLST_Dispersal_VAR_00_08$SPG_PER*100 ~ NTLST_Dispersal_VAR_00_08$Year | NTLST_Dispersal_VAR_00_08$District,
>         data=NTLST_Dispersal_VAR_00_08,
>         horizontal=FALSE,
>         stack=TRUE,
>         layout=c(5,5),
>         xlab="Year",
>         ylab="%",
>         strip = strip.custom( bg="light gray")
>         #par.settings = simpleTheme(col = c("dark gray", "light gray", "white")),
>         #auto.key=TRUE
>         )
>
>
>
> vars<-xyplot(sqrt(NTLST_Dispersal_VAR_00_08$Infestation_NUM) + NTLST_Dispersal_VAR_00_08$AI  ~ NTLST_Dispersal_VAR_00_08$Year | NTLST_Dispersal_VAR_00_08$District,
> data=NTLST_Dispersal_VAR_00_08,
> layout=c(5,5),
> type="b",
> ylab="Square roots of number of infested cells/Landscape aggregation index"
> #par.settings = simpleTheme(col = c("black", "black"), pch=c(16,17))
> )
>
> doubleYScale(dispersal, vars,add.ylab2 = TRUE,
> #auto.key=list(text=c("LDP","SPP", "SPG","Infestation","Landscape aggregation index"),
> #         points = list(pch=c(16,17)), lines=list(lty=c(1,2)),
> #         rectangles = list(size=1.7,border="black", col=c("black", "light gray", "white")),
> #         space = "right")
> )
>
> update(trellis.last.object(),
> par.settings = simpleTheme(col = c("dark gray", "light gray", "white"),pch=c(16,17),lty=c(1,2)))
> ###########################################################################
>
> ##############################################################################
> A sample of data used
> ########################
>
> District        Year    SPG_PER SPP_PER LDP_PER SPP_LDP_PER     Infestation_NUM AI
> DAB     1999    0.446808511     0.205673759     0.34751773      0.553191489     461     48.9143
> DAB     2000    0.480769231     0.192307692     0.326923077     0.519230769     332     37.3591
> DAB     2001    0.366141732     0.212598425     0.421259843     0.633858268     663     37.3418
> DAB     2002    0.663366337     0.222772277     0.113861386     0.336633663     791     41.7671
> DAB     2003    0.553278689     0.178278689     0.268442623     0.446721311     2138    54.333
> DAB     2004    0.799204771     0.115308151     0.085487078     0.200795229     2921    62.5666
> DAB     2005    0.824295011     0.106290672     0.069414317     0.175704989     2783    57.9458
> DAB     2006    0.794520548     0.131506849     0.073972603     0.205479452     2210    50.0829
> DAB     2007    0.77972028      0.148601399     0.071678322     0.22027972      2466    54.0918
> DCC     1999    0.844036697     0.105504587     0.050458716     0.155963303     2077    57.9
> DCC     2000    0.7731569       0.096408318     0.130434783     0.2268431       4294    75.5286
> DCC     2001    0.905714286     0.065714286     0.028571429     0.094285714     4302    74.709
> DCC     2002    0.799256506     0.066914498     0.133828996     0.200743494     6095    80.5838
> DCC     2003    0.896703297     0.065934066     0.037362637     0.103296703     7919    85.7303
> DCC     2004    0.887254902     0.068627451     0.044117647     0.112745098     8516    84.7028
> DCC     2005    0.923728814     0.06779661      0.008474576     0.076271186     7759    79.4637
> DCC     2006    0.941935484     0.04516129      0.012903226     0.058064516     6637    74.5994
> DCC     2007    0.890909091     0.072727273     0.036363636     0.109090909     4288    68.593
> DCH     1999    0.691176471     0.161764706     0.147058824     0.308823529     204     38.2682
> DCH     2000    0.245901639     0.151639344     0.602459016     0.754098361     1099    55.3403
> DCH     2001    0.525316456     0.189873418     0.284810127     0.474683544     1350    52.3413
> DCH     2002    0.326599327     0.111111111     0.562289562     0.673400673     9332    88.5776
> DCH     2003    0.797342193     0.102990033     0.099667774     0.202657807     11416   93.0988
> DCH     2004    0.720430108     0.134408602     0.14516129      0.279569892     13120   94.1959
> DCH     2005    0.773480663     0.066298343     0.160220994     0.226519337     13726   93.0554
> DCH     2006    0.943319838     0.032388664     0.024291498     0.056680162     14393   92.2483
> DCH     2007    0.961038961     0.019480519     0.019480519     0.038961039     13729   90.2417
> DCK     1999    0.611111111     0.055555556     0.333333333     0.388888889     75      64.9573
> DCK     2000    0.48    0.04    0.48    0.52    109     60.2273
> DCK     2001    0.511111111     0.111111111     0.377777778     0.488888889     185     56.1514
> DCK     2002    0.6875  0.09375 0.21875 0.3125  202     65.8192
> DCK     2003    0.649122807     0.052631579     0.298245614     0.350877193     332     61.6667
> DCK     2004    1       0       0       0       315     67.156
> DCK     2005    0.541353383     0.157894737     0.30075188      0.458646617     603     57.967
> DCK     2006    0.685314685     0.111888112     0.202797203     0.314685315     912     59.3861
> DCK     2007    0.9     0.075   0.025   0.1     639     55.8722
> ############################################################################
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Felix Andrews / 安福立
Integrated Catchment Assessment and Management (iCAM) Centre
Fenner School of Environment and Society [Bldg 48a]
The Australian National University
Canberra ACT 0200 Australia
M: +61 410 400 963
T: + 61 2 6125 4670
E: felix.andrews at anu.edu.au
CRICOS Provider No. 00120C
-- 
http://www.neurofractal.org/felix/
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: data.txt
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20100604/2e9eec76/attachment.txt>


More information about the R-help mailing list