0

これは、この前の質問に関連する問題です: geom_boxplot drawing error with precomputed values

  • 事前計算された統計のy のみ(2 番目のグラフィックの下) に座標変換を適用すると、geom_boxplot()中央、下、上の行が消えます。初めて解像度の問題について考えましたが、高解像度(600 dpi)でエクスポートすると、同じ問題が発生します:(

  • x と y (下から 3 番目のグラフィック) に座標変換を適用してランク サイズのプロットを作成すると、ランク 1 の最初のバーでわかるように、描画に別の問題があるようです。幅を修正する解決策も検索します。ここでは、分布の末尾で変換した後、geom が非常に醜いためです。

ここで、データを生成するための私のコード

mydata<-structure(list(v_rank=1:100,min=c(1876.12908723494,525.833257030355,
479.174444926073,413.317971868729,283.212605297879,272.271743111746,
271.218577609491,261.097920232602,249.848244413854,239.6826693619,
221.953200543177,220.672797573803,217.788754899515,209.693597246165,
207.920376492108,206.305695354979,205.224940348855,198.158941191935,
196.768964078812,192.524762910127,190.659747088907,187.313079645817,
184.003802843274,181.124789727041,172.404693867801,168.185940418452,
162.525847977172,159.766160562022,159.47498997248,158.707407613974,
156.670643391483,154.782348653747,151.120608890216,148.537185644508,
147.418985792071,144.192949577012,143.081876591813,138.306500760138,
138.071720969489,135.819373238595,131.268228360837,131.211745493362,
129.475958752641,128.994697005825,126.919520316827,125.131265913884,
123.530137623397,119.30326498362,118.928750988775,116.785274187946,
112.196408614492,109.613414596662,108.0200018691,103.845334903546,
101.304467892935,100.630402666552,99.4843966733682,98.5423453987657,
95.1549453652298,93.7292405692186,92.1425963507161,88.392923177316,
86.5435376677445,84.2370997228235,81.8582235361675,80.7147556864089,
79.9095336240098,78.099293257082,77.444818889996,77.1554419990025,
76.1887950832748,75.765742105877,74.5715550271922,74.4494960879874,
73.0841135453694,72.6275007405538,71.9226468496817,71.5061513708144,
70.8352606944726,70.3525118381674,69.7966653875959,69.7848999118085,
68.7929488062417,68.5934402557501,67.6439262767344,66.0852928683046,
65.5502632169449,65.0385479217237,62.8960922184903,62.842868824982,
61.6430225651763,60.4182651467017,58.0527914522183,54.5733785363583,
51.8253107330044,51.5017948039077,49.3949677412271,44.4040392215262,
39.0000000000002,38.0000000000002),mean=c(8935.04834297135,
3438.53136055906,1370.10037064766,696.649339732745,564.855550869384,
477.749012732246,428.230275841222,396.2810212305,365.13402841522,
348.101058211078,329.525549400666,312.655267601672,298.714290600488,
286.578596825919,274.745155007507,265.597528393185,257.285214286721,
248.522991823508,239.359718910267,231.499756562578,224.770918544173,
217.887544860738,211.93512246229,205.700872047368,200.961757233366,
195.483220118819,190.703032490177,186.38611573552,183.232451708758,
179.680100025236,175.530838577876,172.143924929885,168.603751064018,
165.531924095968,162.821230088091,159.966306235412,157.276891856026,
154.718502961082,152.373606667626,149.793054166436,147.183183846565,
144.697301211638,142.092698673904,139.325636562338,136.985294657696,
134.884798028695,132.553014911682,129.708010287681,127.335105410515,
124.666660146052,122.198967268253,119.658340298511,116.91633635842,
114.585295497153,111.794558546531,109.348226917333,107.359283476062,
105.505531018795,103.599182793896,101.330969375811,99.2715636318623,
96.8198217584668,94.4018562740329,91.6021612575079,88.8560628257584,
86.2825680244354,84.6557538283325,83.1538874988065,81.8670731558834,
80.646504385465,79.5552381339603,78.6038624869326,77.8254005050736,
77.0633271181373,76.2307825731926,75.5818495078455,74.9159235572713,
74.2970580048307,73.7608647918991,73.1324988412481,72.4781145905903,
71.8682133108331,71.2002174199292,70.513258124492,69.7865642378299,
68.9249679265053,68.0937017609885,67.2946458442807,66.2734718903334,
65.5194270252636,64.616142038666,63.3815533937079,61.6228877586886,
59.3146024340077,54.6871823375137,53.4142211437341,52.2392567481353,
48.4217638762252,42.5111837553523,40.7700954890499),med=c(9814.40198510858,
3116.03711391275,1075.34902925081,673.838430955518,545.182921010037,
469.385842176791,416.33971886279,391.928714019644,363.610825228356,
348.167435758967,333.991060074654,314.269940600539,298.076343382389,
289.621613390752,278.280673551311,265.045605562845,257.531074315465,
250.654024557183,238.475372323999,231.249049068254,225.369614181594,
217.30045454174,210.62004470785,205.125786317327,200.071352506748,
193.766926196028,189.43090014115,186.005954812098,183.144335619686,
179.336627990153,175.459033786895,172.101776417078,168.082171205195,
164.87350114018,163.0866752049,159.079687930539,156.794367244073,
155.025803017927,152.225447389848,149.738781054841,146.655021999848,
143.568556751724,141.49663985492,138.771902285413,136.625694031028,
134.478260782788,132.466577693098,129.500757141275,126.915278355084,
124.877995672493,121.658540202601,119.197416394838,116.795154251343,
114.781249998192,111.860236693927,109.202517049202,106.926158862568,
105.409934963418,103.651881321872,101.259922781486,99.5075568481973,
96.8708296894636,94.2131873866587,91.6713809113473,88.8877315210602,
86.5959609936891,84.6564926236535,83.0706199616536,81.8338750812769,
80.4904194574623,79.501385404566,78.5601829584153,77.964098030266,
76.9330786117685,76.1180566937014,75.4631032445209,74.867552690578,
74.1822043037015,73.8209530924406,73.1141361264409,72.4759524530703,
71.7175520392203,71.037938525555,70.4543040600221,69.7018063042958,
68.9299758261986,68.0825783837955,67.2852741246417,66.3571510484087,
65.5355188281136,64.8188102941395,63.4951682075293,61.8032737668676,
59.2751489826056,54.6139464513163,53.3158469970988,52.2498721906628,
48.1225168815051,42.4170341449923,40.8497627061483),max=c(10147.8592830916,
8633.90688162628,4886.70192987259,1240.91225422784,1089.08051129437,
742.719356156879,683.171612433623,578.593555269702,497.93606268059,
476.736825787664,409.969180375468,389.676300445944,381.794925302163,
357.435324255315,355.440016611572,351.494592111432,348.922507989906,
342.6697349814,325.836862890568,272.490173315169,259.108318277361,
246.67353086611,241.084957301967,231.595391911806,228.493098288313,
224.413217462653,219.814039785869,206.939679326569,206.832822873075,
204.588105225262,191.159016060565,189.247627946495,185.888373894867,
179.896261122406,178.4706325079,174.739278352249,173.273333806994,
170.82302532665,168.998600410821,167.186223006948,162.188512084591,
158.981616143302,157.948216962222,153.895398821425,152.404490394739,
152.29624128978,151.757695059315,151.681549938741,148.639740700113,
136.958110443491,134.270180841863,133.893910030369,126.646788409391,
125.055039316004,121.287517319267,117.015374509952,116.36527440479,
113.699942971893,111.979991137726,108.240534045998,105.985702213076,
104.322725137889,100.974271559617,99.5096167709053,95.2936620796326,
92.062366512545,90.0342406215312,89.6481410473251,87.1324204227002,
86.8589880937485,83.8473315574837,83.4339147193383,82.0475214795012,
81.0745398315444,79.3887304257836,78.8784148261601,77.4614289529577,
77.0771790476472,76.0668242500696,75.5540036829177,75.4621857290579,
75.1311008651877,74.2673199628139,74.2641997252619,73.5571399399056,
72.894975554323,71.5629969887197,71.4068442120744,69.2509007389552,
68.5602150275453,67.5652881735352,66.5751462232598,65.5641149484878,
65.2163952942519,58.8526259048984,55.9301169855317,54.7251125558506,
53.3473055854337,46.7221311218048,43.7096043155307),sd=c(1920.61995076318,
2071.90462753791,846.925532656194,166.304459052339,122.67856721787,
81.8151099480816,73.2074776878918,61.8626056929879,45.6856024744788,
43.9017650562536,36.9989421854618,33.3517567028942,32.1410405122589,
28.4758117549672,27.2385799664792,26.2706694900935,24.8927806414279,
22.8309322770636,19.8543548064944,17.0858748338659,14.8944478364513,
13.9737233320454,13.6956203984614,12.5761524668905,11.7549301732758,
11.0988662535768,10.6547736595848,9.76351153623029,9.67890144083554,
8.92810457440155,8.25769486510607,7.54133350871369,6.94842881555269,
6.93147596748886,7.07317885442362,7.07778605646362,6.55489414156632,
6.75841318729736,6.46389598231023,6.15064520603789,6.00065720940157,
6.03502938812419,5.8465959548099,5.53045143365509,5.6569022817063,
5.56619691573112,5.30620580297752,5.4766542946062,4.75121437486975,
4.13369122071181,4.41131211773525,4.10508635820112,3.82638153445188,
3.68736674916447,3.52897983983376,3.41037506985167,3.22536343697251,
3.10065674420964,3.03330450751443,2.9904932686081,2.93861988370156,
3.16712174539256,3.07383178775358,3.13846734678265,2.90733636918161,
2.57176797270246,2.23187444725688,2.29607813738596,2.08303964064532,
1.80338138606924,1.62612534909916,1.54707708046367,1.49240001940341,
1.40939977389337,1.27823705485513,1.21922358651095,1.12806129340388,
1.13010155946996,1.11928430703033,1.04558731836885,1.14995957788824,
1.12521793647851,1.07795527050143,1.01369234716728,1.05350541107726,
1.0912874094653,1.05339501229828,1.11468264457309,1.09260544728007,
1.14912216836883,1.22303957638847,1.25937354563769,1.52953327119146,
1.85172364578356,1.26978526426211,0.861852422307316,1.04440221036651,
1.76492071874432,1.46775534258985,1.3260977569218),ymin=c(7014.42839220817,
1366.62673302115,523.174837991462,530.344880680406,442.176983651514,
395.933902784165,355.02279815333,334.418415537512,319.448425940741,
304.199293154824,292.526607215204,279.303510898778,266.573250088229,
258.102785070952,247.506575041027,239.326858903091,232.392433645293,
225.692059546444,219.505364103772,214.413881728712,209.876470707722,
203.913821528692,198.239502063828,193.124719580478,189.20682706009,
184.384353865242,180.048258830592,176.62260419929,173.553550267923,
170.751995450834,167.27314371277,164.602591421172,161.655322248466,
158.600448128479,155.748051233667,152.888520178949,150.72199771446,
147.960089773785,145.909710685316,143.642408960398,141.182526637163,
138.662271823514,136.246102719094,133.795185128683,131.32839237599,
129.318601112963,127.246809108704,124.231355993075,122.583891035645,
120.532968925341,117.787655150518,115.55325394031,113.089954823969,
110.897928747988,108.265578706697,105.937851847482,104.133920039089,
102.404874274585,100.565878286382,98.3404761072033,96.3329437481607,
93.6527000130742,91.3280244862793,88.4636939107252,85.9487264565768,
83.7108000517329,82.4238793810756,80.8578093614205,79.7840335152381,
78.8431229993958,77.9291127848611,77.0567854064689,76.3330004856702,
75.653927344244,74.9525455183375,74.3626259213346,73.7878622638674,
73.1669564453608,72.6415804848688,72.0869115228792,71.328155012702,
70.7429953743546,70.1222621494278,69.4995657773247,68.7330588267527,
67.83368051704,67.0403067486902,66.1799631997076,65.1808664430534,
64.3703048568947,63.3931024622775,62.1221798480702,60.0933544874972,
57.4628787882242,53.4173970732516,52.5523687214268,51.1948545377688,
46.6568431574809,41.0434284127625,39.4439977321281),ymax=c(10855.6682937345,
5510.43598809697,2217.02590330385,862.953798785084,687.534118087253,
559.564122680328,501.437753529113,458.143626923488,410.819630889699,
392.002823267331,366.524491586128,346.007024304567,330.855331112747,
315.054408580886,301.983734973986,291.868197883278,282.177994928149,
271.353924100571,259.214073716761,248.585631396444,239.665366380624,
231.861268192783,225.630742860751,218.277024514259,212.716687406642,
206.582086372396,201.357806149762,196.14962727175,192.911353149594,
188.608204599638,183.788533442982,179.685258438599,175.552179879571,
172.463400063457,169.894408942514,167.044092291876,163.831785997593,
161.47691614838,158.837502649936,155.943699372474,153.183841055966,
150.732330599762,147.939294628713,144.856087995993,142.642196939403,
140.450994944426,137.859220714659,135.184664582288,132.086319785385,
128.800351366764,126.610279385988,123.763426656712,120.742717892872,
118.272662246317,115.323538386364,112.758601987185,110.584646913034,
108.606187763004,106.63248730141,104.32146264442,102.210183515564,
99.9869435038593,97.4756880617865,94.7406286042905,91.76339919494,
88.8543359971379,86.8876282755894,85.4499656361925,83.9501127965287,
82.4498857715343,81.1813634830595,80.1509395673963,79.3178005244771,
78.4727268920307,77.5090196280478,76.8010730943565,76.0439848506752,
75.4271595643007,74.8801490989295,74.1780861596169,73.6280741684785,
72.9934312473116,72.2781726904307,71.5269504716593,70.8400696489072,
70.0162553359706,69.1470967732868,68.4093284888538,67.3660773376135,
66.6685491936324,65.8391816150544,64.6409269393456,63.1524210298801,
61.1663260797913,55.9569676017759,54.2760735660415,53.2836589585018,
50.1866845949695,43.9789390979422,42.0961932459717)),.Names=c("v_rank",
"min","mean","med","max","sd","ymin","ymax"),row.names=c(NA,
-100L),class="data.frame")

ここで、座標変換を含まないグラフィック

library("ggplot2")

rk<- ggplot(mydata, aes(x = v_rank, y=med, width=0.8, lower = mean - sd, upper = mean + sd, middle = mean, ymin = min, ymax = max, group = v_rank )) + geom_point(colour="blue")

rk <- rk + geom_boxplot(stat="identity",alpha=.3,fatten=2)

rk<- rk  + theme_bw() + xlab('Rank of cities') + ylab('Population of cities')

plot(rk)

ggsave("myplotA.png", dpi=800)

ここに画像の説明を入力

y 座標変換あり:

library("ggplot2")

rk<- ggplot(mydata, aes(x = v_rank, y=med, width=0.5, lower = mean - sd, upper = mean + sd, middle = mean, ymin = min, ymax = max, group = v_rank )) + geom_point(colour="blue")

rk <- rk + geom_boxplot(stat="identity",alpha=.3,fatten=2)

rk<- rk + coord_trans( y = "log10") + theme_bw() + xlab('Rank of cities') + ylab('Population of cities')

plot(rk)

ggsave("myplotB.png", dpi=800)

ご覧のとおり、中央、上部、下部のバーはどこにありますか?)

ここに画像の説明を入力

x および y 座標変換を使用する (**作成したいグラフィックには、x および y 座標変換が含まれています。これはランク サイズ プロットです **):

library("ggplot2")

rk<- ggplot(mydata, aes(x = v_rank, y=med, width=0.5, lower = mean - sd, upper = mean + sd, middle = mean, ymin = min, ymax = max, group = v_rank )) + geom_point(colour="blue")

rk <- rk + geom_boxplot(stat="identity",alpha=.3,fatten=2)

rk<- rk + coord_trans(x="log10", y = "log10") + theme_bw() + xlab('Rank of cities') + ylab('Population of cities')

plot(rk)

ggsave("myplotC.png", dpi=800)

ここに画像の説明を入力

4

1 に答える 1

1

最初の行に問題が(max< mean+sd)あるため、奇妙な最初のボックスがあります。対数スケールのものはより小さい値に圧縮されるため、残りの下限はわずかです。

それはバグではなく機能です。

対称にしたい場合は、生データをログに記録し、その上でsd、mean、std errorを計算することを意味します。次に、ログに記録された要約を通常の空間にプロットします。

于 2012-11-28T14:31:02.793 に答える