0

有人可以建议我如何控制汽车包的散点图功能中的图例框吗?对于我的数据集,我使用以下命令获得的图例框与绘图相比成比例地大。

library(car)
scatterplot(x+y ~ year|id, data = df, 
      reg = F, log = "y",  legend.coords = "bottomright", cex = 0.7)

我的数据是

> df
    year      id          x          y
1   1991 IDN_MYS   11437744    2774605
2   1992 IDN_MYS    8943531   34206880
3   1993 IDN_MYS   12198708   99868773
4   1994 IDN_MYS   38682942   87117483
5   1995 IDN_MYS   34296437  105040113
6   1996 IDN_MYS   51821888  112274280
7   1997 IDN_MYS   70006229   74435308
8   1998 IDN_MYS  127004193   46872739
9   1999 IDN_MYS   62566372   23214132
10  2000 IDN_MYS  289045135   62313636
11  2001 IDN_MYS  229997303   57084941
12  2002 IDN_MYS  279365245   76471563
13  2003 IDN_MYS  312307349   81738843
14  2004 IDN_MYS  343559119  138253636
15  2005 IDN_MYS  471477298  140554543
16  2006 IDN_MYS  455329809  139719247
17  2007 IDN_MYS  401328444  176776471
18  2008 IDN_MYS  565098964  624252516
19  2009 IDN_MYS  473096168  439215785
20  2010 IDN_MYS  599996117  740172389
21  2011 IDN_MYS  716575345  896620515
22  2012 IDN_MYS  788423299 1019096755
23  1996 PHL_MYS  549983467  213103928
24  1997 PHL_MYS  439449916  357070365
25  1998 PHL_MYS  931142627  411497229
26  1999 PHL_MYS 1255531969  387415600
27  2000 PHL_MYS 1152540687  618425906
28  2001 PHL_MYS  770483540  444234081
29  2002 PHL_MYS 1265422714  837094577
30  2003 PHL_MYS 1993114374  756890867
31  2004 PHL_MYS 1603033289 1014553499
32  2005 PHL_MYS 1694810322  668611570
33  2006 PHL_MYS 1573916299  887877892
34  2007 PHL_MYS 1300465702  864579934
35  2008 PHL_MYS  821082794  601184705
36  2009 PHL_MYS  472922751  434354451
37  2010 PHL_MYS  185357639  633218667
38  2011 PHL_MYS  200507062  266285496
39  2012 PHL_MYS  393501169  567367958
40  1991 IDN_PHL      28447     250090
41  1992 IDN_PHL     190776     101914
42  1993 IDN_PHL      58302    1335777
43  1994 IDN_PHL      87137    2060608
44  1995 IDN_PHL    1850229     931570
45  1996 IDN_PHL    3644638    2160783
46  1997 IDN_PHL   29971288    3152450
47  1998 IDN_PHL   19238811    1164557
48  1999 IDN_PHL   45561556   10196835
49  2000 IDN_PHL   90547227   22258828
50  2001 IDN_PHL   69838301    7199140
51  2002 IDN_PHL   95666176   14672929
52  2003 IDN_PHL  112501700   21867852
53  2004 IDN_PHL  109084814   38960824
54  2005 IDN_PHL  138664527   56658947
55  2006 IDN_PHL  125767320   25394112
56  2007 IDN_PHL  207796585   30196264
57  2008 IDN_PHL  316269770  213803274
58  2009 IDN_PHL  334796270  128378781
59  2010 IDN_PHL  559649987  177062428
60  2011 IDN_PHL  591243237  233786671
61  2012 IDN_PHL  621525781  211074568
62  1991 IDN_SGP  111331217  106837577
63  1992 IDN_SGP  200168757   93172782
64  1993 IDN_SGP  369577514  176230513
65  1994 IDN_SGP  724396934  160347397
66  1995 IDN_SGP  859375579  232592106
67  1996 IDN_SGP 1053938233  209213186
68  1997 IDN_SGP  992362148  240561721
69  1998 IDN_SGP  837762374  129096919
70  1999 IDN_SGP 1237983442  150479574
71  2000 IDN_SGP 1884383174  172757104
72  2001 IDN_SGP 1496665235  167477393
73  2002 IDN_SGP 1479084168  172725784
74  2003 IDN_SGP 1731257432  151655786
75  2004 IDN_SGP 1699137343  204201123
76  2005 IDN_SGP 2467031469  284016205
77  2006 IDN_SGP 2275585685  265739398
78  2007 IDN_SGP 2161770346  328938399
79  2008 IDN_SGP 2146608437 3150499289
80  2009 IDN_SGP 1571218299 2133235054
81  2010 IDN_SGP 2372797621 2626231916
82  2011 IDN_SGP 2754312146 2740425339
83  2012 IDN_SGP 2701556151 2451688915
84  1991 MYS_SGP   85321250   76391376
85  1993 MYS_SGP  102928625  112192464
86  1994 MYS_SGP  141788962  122642426
87  1995 MYS_SGP  167470600  122437307
88  1996 MYS_SGP  158946161  100285623
89  1997 MYS_SGP 2156717371 2232542905
90  1998 MYS_SGP 1913041719 1995282281
91  1999 MYS_SGP  806513802  967322242
92  2000 MYS_SGP  871129661 1046264147
93  2001 MYS_SGP  638170363  733835658
94  2002 MYS_SGP  612926344  741803018
95  2003 MYS_SGP  830731960  740708203
96  2004 MYS_SGP 7508222782 3526815135
97  2005 MYS_SGP 7874168269 4064855561
98  2006 MYS_SGP 9189427786 4648990581
99  2007 MYS_SGP 3772131014 2526345820
100 2008 MYS_SGP 2764991070 2480646122
101 2009 MYS_SGP 2661743660 2216756423
102 2010 MYS_SGP 4664322857 3242487021
103 2011 MYS_SGP 4980172900 4252241858
104 2012 MYS_SGP 3839690439 3712060524
105 1996 PHL_SGP  837610701  414819289
106 1997 PHL_SGP 1104938914  622262905
107 1998 PHL_SGP 1310047928  525549312
108 1999 PHL_SGP 1861189682  591011046
109 2000 PHL_SGP 2342945398  977510027
110 2001 PHL_SGP 1694469905  914255876
111 2002 PHL_SGP 1906445571 1080698868
112 2003 PHL_SGP 1765768520 1214806039
113 2004 PHL_SGP 1803823032 1525976047
114 2005 PHL_SGP 1867147463 1438535823
115 2006 PHL_SGP 2189432899 1540267238
116 2007 PHL_SGP 1947116494 2532441282
117 2008 PHL_SGP 1389989850 2351075257
118 2009 PHL_SGP 1860741791 1277515268
119 2010 PHL_SGP 1032873170 1677221157
120 2011 PHL_SGP 1453386627  804526148
121 2012 PHL_SGP 3181769066 1488345868
122 1991 IDN_THA    2140771   13705007
123 1992 IDN_THA    3187459    8238929
124 1993 IDN_THA    4522221   18438515
125 1994 IDN_THA   15964978   20468019
126 1995 IDN_THA   29973720   29684871
127 1996 IDN_THA   43793727   59862242
128 1997 IDN_THA   52517486   36806490
129 1998 IDN_THA   50158763   10171907
130 1999 IDN_THA   77506279   15441506
131 2000 IDN_THA  138271465   77898164
132 2001 IDN_THA  138479659   99650501
133 2002 IDN_THA  168933278  167551562
134 2003 IDN_THA  230749188  333490268
135 2004 IDN_THA  352507276  673490261
136 2005 IDN_THA  365938735  933081200
137 2006 IDN_THA  352808090  775750111
138 2007 IDN_THA  401339501  980019932
139 2008 IDN_THA  576939213 1895591254
140 2009 IDN_THA  478071439 1123711689
141 2010 IDN_THA  764442260 2139028565
142 2011 IDN_THA  815339722 2923520295
143 2012 IDN_THA 1424049780 3323590714
144 1991 MYS_THA    2468294    2477877
145 1992 MYS_THA    4271707    4278919
146 1993 MYS_THA    3945514    8354463
147 1994 MYS_THA    7018894    9345858
148 1995 MYS_THA   16031863    7703535
149 1996 MYS_THA   21703443    8364449
150 1997 MYS_THA  216105303  421718141
151 1998 MYS_THA  192242613  291695740
152 1999 MYS_THA  202199887  282542761
153 2000 MYS_THA  330644181  335800886
154 2001 MYS_THA  347658354  344837915
155 2002 MYS_THA  575998103  366711107
156 2003 MYS_THA  393448317  419190822
157 2004 MYS_THA 1394809514 1464170016
158 2005 MYS_THA 1245886723 1740648388
159 2006 MYS_THA 1415834408 1950525442
160 2007 MYS_THA  840306185 1445242868
161 2008 MYS_THA 1138789586 1902945473
162 2009 MYS_THA 1170828145 1929917005
163 2010 MYS_THA 1307287187 2865034688
164 2011 MYS_THA 1274878221 2611106076
165 2012 MYS_THA 1544870185 2842557647
166 1996 PHL_THA  137253990   68177095
167 1997 PHL_THA  175664673  127278929
168 1998 PHL_THA  162187945  156879200
169 1999 PHL_THA  287133506  145406083
170 2000 PHL_THA  462123957  203379338
171 2001 PHL_THA  463842716  191143666
172 2002 PHL_THA  528406424  364431743
173 2003 PHL_THA  519291379  616732520
174 2004 PHL_THA  671229176  683825235
175 2005 PHL_THA  642038953  724811281
176 2006 PHL_THA  567342165  938688336
177 2007 PHL_THA  526155022  726385210
178 2008 PHL_THA  636726655  841035044
179 2009 PHL_THA  467039548  911615064
180 2010 PHL_THA  731990688 1308429373
181 2011 PHL_THA  629375098  682891424
182 2012 PHL_THA 1554349870 1113062087
183 1991 SGP_THA   10885224   14434356
184 1992 SGP_THA   13301933   18519681
185 1993 SGP_THA   17527631   30896302
186 1994 SGP_THA   27186774   31598410
187 1995 SGP_THA   39201011   22036473
188 1996 SGP_THA   42795153   20493725
189 1997 SGP_THA   46804207   20810049
190 1998 SGP_THA   28287459   19933156
191 1999 SGP_THA  271462441  118264500
192 2000 SGP_THA 1723827912 1095006316
193 2001 SGP_THA 1552028188  912616596
194 2002 SGP_THA 1741408148 1115064328
195 2003 SGP_THA 2559196286 1858716114
196 2004 SGP_THA 3125629156 2074432347
197 2005 SGP_THA 3534766631 2065086462
198 2006 SGP_THA 3301643703 2175621248
199 2007 SGP_THA 1295593122  902245386
200 2008 SGP_THA 1424818080  989979788
201 2009 SGP_THA 1040654297  759087095
202 2010 SGP_THA 1196212750  870255138
203 2011 SGP_THA 1252195900  703173938
204 2012 SGP_THA  215978470  109490987
205 1993 IDN_VNM     323608       5924
206 1995 IDN_VNM      77036      58448
207 1996 IDN_VNM    1389526     275001
208 1997 IDN_VNM     293601    5046313
209 1998 IDN_VNM    1987282      75197
210 1999 IDN_VNM     983189     371569
211 2000 IDN_VNM    4140480     137160
212 2001 IDN_VNM    4284367    1671176
213 2002 IDN_VNM    7737052    1516206
214 2003 IDN_VNM   16951627    2554513
215 2004 IDN_VNM   46395314    3911078
216 2005 IDN_VNM   64741409    7865052
217 2006 IDN_VNM  125423755    8309694
218 2007 IDN_VNM  111314828   10359260
219 2008 IDN_VNM  154163948   40498944
220 2009 IDN_VNM  116038617   75212900
221 2010 IDN_VNM  113561781   77692878
222 2011 IDN_VNM  150702019  126604098
223 2012 IDN_VNM  224982660  122391042
224 1997 MYS_VNM   30144156    7913068
225 1998 MYS_VNM   84640626    6671372
226 1999 MYS_VNM   55829650    5056846
227 2000 MYS_VNM   75951596    6084615
228 2001 MYS_VNM   19596593    4614169
229 2002 MYS_VNM   34578033    6226961
230 2003 MYS_VNM   40798458    9740543
231 2004 MYS_VNM   67420147   23111748
232 2005 MYS_VNM   64953133   20362987
233 2006 MYS_VNM   77165313   25546626
234 2007 MYS_VNM  136490949   42663540
235 2008 MYS_VNM  140692752   45481847
236 2009 MYS_VNM  108173172   70128670
237 2010 MYS_VNM  291976224  126513276
238 2011 MYS_VNM  301534014  343877802
239 2012 MYS_VNM  390141547  779085608
240 1996 PHL_VNM     959311   26149104
241 1997 PHL_VNM    1192118  130437626
242 1998 PHL_VNM    4310119  196834190
243 1999 PHL_VNM    1836874   43147782
244 2000 PHL_VNM     476663     907483
245 2001 PHL_VNM    2689326  135383002
246 2002 PHL_VNM    1826093  114998138
247 2003 PHL_VNM    6808062  132974547
248 2004 PHL_VNM   31182773  175702949
249 2005 PHL_VNM   25761849  176135394
250 2006 PHL_VNM   38810899   98909296
251 2007 PHL_VNM   43719869   87381077
252 2008 PHL_VNM   53667853   56194466
253 2009 PHL_VNM   41153612   38097737
254 2010 PHL_VNM   74189476   57676747
255 2011 PHL_VNM  146845059   64167991
256 2012 PHL_VNM  120151210   59638781
257 1997 SGP_VNM    8060072    2600160
258 1998 SGP_VNM    1209034      42116
259 1999 SGP_VNM   27125282     706523
260 2000 SGP_VNM  147698509   17401640
261 2001 SGP_VNM  113376942   14875786
262 2002 SGP_VNM  125533288   21347946
263 2003 SGP_VNM  185391885   41694070
264 2004 SGP_VNM  247668686   55761527
265 2005 SGP_VNM  303272984   50896968
266 2006 SGP_VNM  420135025   51485979
267 2007 SGP_VNM  239439988   42562198
268 2008 SGP_VNM  392688720   77730844
269 2009 SGP_VNM  293104237  101637444
270 2010 SGP_VNM  380838132  140924699
271 2011 SGP_VNM  506546411  245321530
272 2012 SGP_VNM   99698644   45997624
273 1994 THA_VNM   13725761     309243
274 1995 THA_VNM     398504      57388
275 1996 THA_VNM    2895880    7419160
276 1997 THA_VNM    1990150  134537513
277 1998 THA_VNM    6081248  174528771
278 1999 THA_VNM   55049996  164882260
279 2000 THA_VNM  140617357  203560997
280 2001 THA_VNM   96488254  169326211
281 2002 THA_VNM  110053328   84673727
282 2003 THA_VNM  120661225  137308864
283 2004 THA_VNM  152581213  214213301
284 2005 THA_VNM  217110782  227155786
285 2006 THA_VNM  237419798   82152020
286 2007 THA_VNM  403468759  131883212
287 2008 THA_VNM  545576906  160572811
288 2009 THA_VNM  590470215  223879429
289 2010 THA_VNM  616222294  382399594
290 2011 THA_VNM  807938367  539802245
291 2012 THA_VNM  487517628  242259411
4

1 回答 1

1

我会scatterplot使用 覆盖图例选项legend.plot = F,因为它似乎受到限制并创建我自己的图例,如下所示

library(car)
scatterplot(x+y ~ year|id, data = df, reg = F, log = "y", legend.plot = F)
legend(title = "id", "bottomright", legend=unique(df$id), pch = seq_len(length(unique(df$id))), pt.cex=0.7, cex=0.7, col = seq_len(length(unique(df$id)))) 

在此处输入图像描述

编辑

对于多列图例使用ncol

library(car)
scatterplot(x+y ~ year|id, data = df, reg = F, log = "y", legend.plot = F)
legend(title = "id", "bottomright", legend=unique(df$id), pch = seq_len(length(unique(df$id))), pt.cex=0.7, cex=0.7, col = seq_len(length(unique(df$id))), ncol = 2) 

在此处输入图像描述

于 2014-05-25T10:40:20.283 回答