使用传统方法时,绘图标题不会显示在两行上

时间:2016-08-26 01:08:00

标签: r ggplot2 plotly

乍一看,这很简单,但我已经使用了我找到的解决方案here,但它并不适合我。

以下是我用于剧情的代码:

# interactive plot with ribbon
test <- ggplot(data = wide.data, aes(x = Games, y = Prediction)) +
  geom_ribbon(aes(ymin = Lower, ymax = Upper, fill = League), alpha = .5) + 
  geom_point() + 
  labs(x = "Number of Games Played", y = "Total Number of Goals") + scale_y_continuous(breaks=seq(0,70,5)) +
  scale_x_continuous(breaks=seq(0,50,5)) + theme_light() +
  labs(title = 'Prediction lines and Confidence Intervals \n for Six Leagues') + 
  theme(plot.title = element_text(size = 15)) +
  theme(plot.title = element_text(hjust = 0.5))

ggplotly(test)

This is the output I'm getting

我错过了一些明显的东西吗?对不起,如果这不是一个特别有用的问题。

编辑:添加以下数据源:

> dput(wide.data)
structure(list(Games = c(1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 
2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 
5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 
7L, 8L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 10L, 10L, 
10L, 10L, 10L, 10L, 11L, 11L, 11L, 11L, 11L, 11L, 12L, 12L, 12L, 
12L, 12L, 12L, 13L, 13L, 13L, 13L, 13L, 13L, 14L, 14L, 14L, 14L, 
14L, 14L, 15L, 15L, 15L, 15L, 15L, 15L, 16L, 16L, 16L, 16L, 16L, 
16L, 17L, 17L, 17L, 17L, 17L, 17L, 18L, 18L, 18L, 18L, 18L, 18L, 
19L, 19L, 19L, 19L, 19L, 19L, 20L, 20L, 20L, 20L, 20L, 20L, 21L, 
21L, 21L, 21L, 21L, 21L, 22L, 22L, 22L, 22L, 22L, 22L, 23L, 23L, 
23L, 23L, 23L, 23L, 24L, 24L, 24L, 24L, 24L, 24L, 25L, 25L, 25L, 
25L, 25L, 25L, 26L, 26L, 26L, 26L, 26L, 26L, 27L, 27L, 27L, 27L, 
27L, 27L, 28L, 28L, 28L, 28L, 28L, 28L, 29L, 29L, 29L, 29L, 29L, 
29L, 30L, 30L, 30L, 30L, 30L, 30L, 31L, 31L, 31L, 31L, 31L, 31L, 
32L, 32L, 32L, 32L, 32L, 32L, 33L, 33L, 33L, 33L, 33L, 33L, 34L, 
34L, 34L, 34L, 34L, 34L, 35L, 35L, 35L, 35L, 35L, 35L, 36L, 36L, 
36L, 36L, 36L, 36L, 37L, 37L, 37L, 37L, 37L, 37L, 38L, 38L, 38L, 
38L, 38L, 38L), League = c("BLI", "BPL", "LG1", "LGA", "MLS", 
"SRA", "BLI", "BPL", "LG1", "LGA", "MLS", "SRA", "BLI", "BPL", 
"LG1", "LGA", "MLS", "SRA", "BLI", "BPL", "LG1", "LGA", "MLS", 
"SRA", "BLI", "BPL", "LG1", "LGA", "MLS", "SRA", "BLI", "BPL", 
"LG1", "LGA", "MLS", "SRA", "BLI", "BPL", "LG1", "LGA", "MLS", 
"SRA", "BLI", "BPL", "LG1", "LGA", "MLS", "SRA", "BLI", "BPL", 
"LG1", "LGA", "MLS", "SRA", "BLI", "BPL", "LG1", "LGA", "MLS", 
"SRA", "BLI", "BPL", "LG1", "LGA", "MLS", "SRA", "BLI", "BPL", 
"LG1", "LGA", "MLS", "SRA", "BLI", "BPL", "LG1", "LGA", "MLS", 
"SRA", "BLI", "BPL", "LG1", "LGA", "MLS", "SRA", "BLI", "BPL", 
"LG1", "LGA", "MLS", "SRA", "BLI", "BPL", "LG1", "LGA", "MLS", 
"SRA", "BLI", "BPL", "LG1", "LGA", "MLS", "SRA", "BLI", "BPL", 
"LG1", "LGA", "MLS", "SRA", "BLI", "BPL", "LG1", "LGA", "MLS", 
"SRA", "BLI", "BPL", "LG1", "LGA", "MLS", "SRA", "BLI", "BPL", 
"LG1", "LGA", "MLS", "SRA", "BLI", "BPL", "LG1", "LGA", "MLS", 
"SRA", "BLI", "BPL", "LG1", "LGA", "MLS", "SRA", "BLI", "BPL", 
"LG1", "LGA", "MLS", "SRA", "BLI", "BPL", "LG1", "LGA", "MLS", 
"SRA", "BLI", "BPL", "LG1", "LGA", "MLS", "SRA", "BLI", "BPL", 
"LG1", "LGA", "MLS", "SRA", "BLI", "BPL", "LG1", "LGA", "MLS", 
"SRA", "BLI", "BPL", "LG1", "LGA", "MLS", "SRA", "BLI", "BPL", 
"LG1", "LGA", "MLS", "SRA", "BLI", "BPL", "LG1", "LGA", "MLS", 
"SRA", "BLI", "BPL", "LG1", "LGA", "MLS", "SRA", "BLI", "BPL", 
"LG1", "LGA", "MLS", "SRA", "BLI", "BPL", "LG1", "LGA", "MLS", 
"SRA", "BLI", "BPL", "LG1", "LGA", "MLS", "SRA", "BLI", "BPL", 
"LG1", "LGA", "MLS", "SRA", "BLI", "BPL", "LG1", "LGA", "MLS", 
"SRA", "BLI", "BPL", "LG1", "LGA", "MLS", "SRA"), Lower = c(0.953418277415756, 
0.991908465191337, 0.991908465191337, 0.991908465191337, 1.12586982342001, 
1.024356375271, 1.97777465268675, 1.75489322666377, 1.98381693038267, 
2.08128334547164, 2.25173964684001, 2.13759429471327, 2.8874541222714, 
2.7468016918551, 2.84606348918419, 2.79495251495612, 3.35459366345813, 
2.95045407983961, 3.9118104975424, 3.46047086133959, 3.83797195437552, 
3.78686098014746, 4.4678315829004, 3.9748104551106, 4.82148996712705, 
4.07964277397953, 4.95882053575741, 4.5997207652738, 5.59370140632041, 
4.78767024023694, 5.81339843231838, 5.13055069285498, 6.00972845463285, 
5.55313904268955, 6.72208706857957, 5.55065500170937, 6.4789919090884, 
6.08396897027074, 7.12296637407513, 6.12777963474551, 7.84293564996145, 
6.46033447129402, 7.47090037427973, 6.84695373174317, 8.19526278056753, 
7.1521360100165, 8.95617356940372, 7.41375274870977, 8.54319678077214, 
7.8388621969345, 9.10494225015218, 7.81772948678652, 10.069411488846, 
8.36717102612553, 9.30618154224456, 8.8632185722055, 10.0968507153435, 
8.58071424825894, 11.1826494082883, 9.41807894500097, 10.2980900074359, 
9.57688774168998, 11.1862255956238, 9.63162216713439, 12.2958873277305, 
10.442435320272, 11.2515082848517, 10.4391343004915, 12.2371335144993, 
10.6559785424054, 13.4091252471728, 11.3046818790735, 12.2049265622674, 
11.4634906757625, 13.3265083947796, 11.6093968198211, 14.5349950705928, 
12.3940567593538, 13.2558344811429, 12.3731701453471, 14.377416313655, 
12.5190762894058, 15.6558436519747, 13.2563033181553, 14.2477429463342, 
13.2828496149318, 15.4497127201474, 13.5109847545971, 16.7817134753947, 
14.2806596934263, 15.0606027314605, 14.1925290845164, 16.5006206390229, 
14.5028932197885, 17.9025620567766, 15.3315676123017, 16.0525111966519, 
15.1844375497078, 17.4103001086075, 15.2658779812609, 19.0054160733947, 
16.1444273974281, 17.0059294740676, 16.1378558271235, 18.272546667409, 
16.2577864464522, 20.1312858968147, 17.1363358626194, 17.6715229508376, 
17.0912741045393, 19.2259649448248, 17.1674659160369, 21.2571557202347, 
18.2086322691118, 18.663431416029, 17.8049432740238, 20.1793832222405, 
17.8811350855214, 22.3780043016166, 19.0708788279133, 19.6553398812203, 
18.8292996492948, 21.2687581025208, 18.8730435507127, 23.4912422210589, 
19.8837386130397, 20.6472483464116, 19.8802075681702, 22.3196660213963, 
19.4476841427686, 24.6171120444789, 20.9969765324819, 21.6981562652871, 
20.6431923296426, 23.4329039408386, 20.4011024201844, 25.7303499639212, 
21.9888849976733, 22.6515745427028, 21.635100794834, 24.505200347331, 
21.2139622053107, 26.851198545303, 23.0132413729443, 23.5612540122875, 
22.659457170105, 25.5561082662064, 21.9769469667832, 27.9540525619211, 
24.0375977482153, 24.5531624774788, 23.6513656352963, 26.6070161850819, 
22.9688554319745, 29.0799223853412, 24.8504575333416, 25.5065807548946, 
24.6047839127121, 27.5166956546665, 23.8785349015592, 30.1931603047834, 
25.922753939834, 26.269565516367, 25.5144633822967, 28.378942213468, 
24.5441283783292, 31.3140088861653, 26.947110315105, 27.3418619228594, 
26.5063718474881, 29.2886216830527, 25.4538078479138, 32.4398787095853, 
27.9005285925208, 28.1547217079858, 27.125543760128, 30.1508682418542, 
26.2167926093862, 33.5531166290276, 28.7133883776471, 29.0644011775704, 
28.0352232297126, 31.2402431221345, 27.2087010745776, 34.6789864524476, 
29.6230678472318, 30.0563096427617, 28.9449026992973, 32.2321515873258, 
28.2006095397689, 35.8048562758676, 30.6739757661072, 31.0806660180327, 
29.9368111644886, 33.2240600525172, 29.2515174586444, 36.9307260992876, 
31.7633506463875, 32.1050223933037, 30.6504803339731, 34.344908633899, 
30.2758738339154, 38.0439640187299, 32.7877070216585, NA, 31.6038986113889, 
35.3958165527745, 31.2677822991067, 39.172349680989, 33.5506917831309, 
NA, 32.3668833728613, 36.3877250179658, 32.2212005765225, 40.2855876004313, 
34.6015997020064, NA, 33.3203016502771, 37.3796334831572, 33.3105754568028, 
41.3988255198736, 35.4638462608079, NA, 34.1825482090786, 38.4519298896496, 
34.3349318320738, 42.5016795364917, 36.4172645382237), Prediction = c(1.09815375445633, 
1.14244921317105, 1.14244921317105, 1.14244921317105, 1.56756991682395, 
1.18853138677409, 2.28668514123042, 2.07994244701033, 2.2848984263421, 
2.4806827570886, 3.13513983364789, 2.63690103749515, 3.34226087669724, 
3.22239166018138, 3.29954699334351, 3.38182716040123, 4.52735276656695, 
3.61220927917495, 4.53079226347133, 4.12353606349401, 4.44199620651456, 
4.52427637357228, 5.97572241728801, 4.80074066594904, 5.58636799893815, 
4.95615615314181, 5.9487877292247, 5.49958461525208, 7.54329233411195, 
5.77604890762884, 6.7288172121092, 6.19262849787408, 7.18526007395696, 
6.5977383697084, 9.17409222055659, 6.71354214146812, 7.59502211504602, 
7.2907822523304, 8.63362972467803, 7.39807580873082, 10.6808837432667, 
7.76911787693494, 8.73747132821707, 8.22827548616968, 9.91997678820602, 
8.58660719550491, 12.1292533939878, 8.86727163139127, 10.0238183917451, 
9.37072469934073, 10.9755525236728, 9.45281209844173, 13.5776230447088, 
9.9654253858476, 10.9613116255843, 10.5592560861148, 12.1180017368439, 
10.390305332281, 15.0259926954299, 11.2018977305799, 12.1037608387554, 
11.4604004894275, 13.4562352807614, 11.6267776770133, 16.474362346151, 
12.390429117354, 13.2019145932117, 12.4750490564289, 14.6927076254937, 
12.8153090637874, 17.922731996872, 13.4050776843554, 14.300068347668, 
13.6635804432029, 16.0309411694113, 13.9134628182437, 19.490301913696, 
14.7433112282729, 15.5365406924003, 14.7191561786698, 17.2674135141435, 
14.9690385537105, 20.9970934364061, 15.7579597952743, 16.6789899055714, 
15.7747319141366, 18.5537605776715, 16.1114877668816, 22.5646633532301, 
16.9464911820484, 17.6542981472512, 16.8303076496034, 19.7902329224038, 
17.2539369800526, 24.0714548759402, 18.1829635267807, 18.7967473604222, 
17.9727568627745, 20.8458086578706, 18.1914302138919, 25.4636678088592, 
19.1582717684605, 19.8949011148785, 19.0709106172308, 21.860457224872, 
19.3338794270629, 27.0312377256832, 20.3007209816315, 20.7611060178154, 
20.1690643716871, 22.9586109793284, 20.3894551625298, 28.5988076425071, 
21.5870680451595, 21.9035552309864, 21.0702087749998, 24.0567647337847, 
21.2905995658424, 30.1055991652173, 22.6017166121609, 23.0460044441575, 
22.2587401617738, 25.3949982777022, 22.4330487790135, 31.5539688159383, 
23.5770248538407, 24.1884536573285, 23.4952125065061, 26.6314706224345, 
23.2333862180359, 33.1215387327623, 25.0253945045618, 25.4249260020608, 
24.4327057403454, 28.0798402731556, 24.3315399724922, 34.5699083834834, 
26.1678437177328, 26.5230797565171, 25.5751549535164, 29.3661873366836, 
25.306848214172, 36.0766999061935, 27.3563751045069, 27.5786554919839, 
26.7636863402905, 30.6026596814158, 26.2443414480113, 37.4689128391125, 
28.544906491281, 28.721104705155, 27.9061355534616, 31.8391320261481, 
27.3867906611823, 39.0364827559365, 29.5202147329608, 29.8192584596113, 
29.0042893079179, 32.8947077616149, 28.4423663966492, 40.4848524066576, 
30.8065617964888, 30.7567516934506, 30.0598650433847, 33.9093563286163, 
29.308571299586, 41.9916439293677, 31.9950931832629, 32.0430987569786, 
31.2023142565558, 34.9649320640831, 30.3641470350528, 43.5592138461916, 
33.0932469377192, 33.0184069986584, 32.0349343462036, 35.9795806310846, 
31.3016402688921, 45.0075834969127, 34.068555179399, 34.0739827341252, 
33.0905100816704, 37.3178141750021, 32.4440894820631, 46.5751534137367, 
35.1241309148659, 35.2164319472963, 34.1460858171372, 38.4602633881732, 
33.5865386952342, 48.1427233305606, 36.3606032595981, 36.4049633340703, 
35.2885350303083, 39.6027126013442, 34.8230110399664, 49.7102932473845, 
37.6988368035157, 37.5934947208444, 36.1896794336209, 41.1095041240543, 
36.0115424267405, 51.1586628981056, 38.8873681902898, NA, 37.2878331880772, 
42.3459764687866, 37.1539916399116, 52.7894627845502, 39.824861424129, 
NA, 38.2253264219165, 43.4884256819577, 38.2521453943679, 54.2378324352713, 
41.0613337688613, NA, 39.3234801763728, 44.6308748951287, 39.5903789382855, 
55.6862020859924, 42.0759823358627, NA, 40.3381287433743, 45.9172219586567, 
40.7789103250595, 57.0784150189114, 43.174136090319), Upper = c(1.2428892314969, 
1.29298996115076, 1.29298996115076, 1.29298996115076, 2.00927001022789, 
1.35270639827718, 2.59559562977408, 2.40499166735689, 2.58597992230153, 
2.88008216870556, 4.01854002045577, 3.13620778027703, 3.79706763112308, 
3.69798162850766, 3.75303049750283, 3.96870180584633, 5.70011186967577, 
4.27396447851029, 5.14977402940026, 4.78660126564843, 5.04602045865359, 
5.2616917669971, 7.48361325167562, 5.62667087678747, 6.35124603074926, 
5.83266953230409, 6.93875492269199, 6.39944846523036, 9.4928832619035, 
6.76442757502073, 7.64423599190003, 7.25470630289318, 8.36079169328107, 
7.64233769672725, 11.6260973725336, 7.87642928122687, 8.71105232100364, 
8.49759553439007, 10.1442930752809, 8.66837198271614, 13.518831836572, 
9.07790128257587, 10.0040422821544, 9.6095972405962, 11.6446907958445, 
10.0210783809933, 15.3023332185719, 10.3207905140728, 11.504440002718, 
10.902587201747, 12.8461627971935, 11.0878947100969, 17.0858346005717, 
11.5636797455697, 12.6164417089241, 12.2552936000241, 14.1391527583443, 
12.1998964163031, 18.8693359825715, 12.9857165161587, 13.9094316700749, 
13.3439132371649, 15.7262449658991, 13.6219331868922, 20.6528373645714, 
14.3384229144359, 15.1523209015718, 14.5109638123662, 17.1482817364882, 
14.9746395851693, 22.4363387465712, 15.5054734896372, 16.3952101330687, 
15.8636702106434, 18.735373944043, 16.2175288166662, 24.4456087567991, 
17.092565697192, 17.8172469036578, 17.0651422119924, 20.1574107146321, 
17.4190008180152, 26.3383432208375, 18.2596162723933, 19.1102368648085, 
18.2666142133414, 21.6578084351956, 18.711990779166, 28.3476132310654, 
19.6123226706705, 20.2479935630418, 19.4680862146904, 23.0798452057847, 
20.0049807403168, 30.2403476951038, 21.0343594412596, 21.5409835241926, 
20.7610761758412, 24.2813172071337, 21.1169824465229, 31.9219195443238, 
22.1721161394929, 22.7838727556895, 22.0039654073381, 25.448367782335, 
22.4099724076737, 33.9311895545517, 23.4651061006436, 23.8506890847931, 
23.246854638835, 26.6912570138319, 23.6114444090227, 35.9404595647796, 
24.9655038212072, 25.1436790459438, 24.3354742759757, 27.9341462453288, 
24.7000640461634, 37.833194028818, 26.1325543964085, 26.4366690070946, 
25.6881806742529, 29.5212384528836, 25.9930540073142, 39.6166954108178, 
27.2703110946418, 27.7296589682454, 27.110217444842, 30.9432752234727, 
27.0190882933031, 41.6259654210457, 29.0538124766416, 29.1516957388344, 
28.2222191510481, 32.7267766054726, 28.2619775248, 43.4094668030456, 
30.3468024377924, 30.3945849703313, 29.5152091121989, 34.2271743260362, 
29.3997342230332, 45.302201267084, 31.6995088360696, 31.5960569716803, 
30.8679155104761, 35.6492110966253, 30.5117359292394, 46.983773116304, 
33.0522152343468, 32.8890469328311, 32.1609054716268, 37.0712478672143, 
31.8047258903901, 48.9930431265318, 34.18997193258, 34.131936164328, 
33.4037947031237, 38.2727198685633, 33.0061978917391, 50.7765445085317, 
35.6903696531436, 35.2439378705341, 34.6052667044727, 39.4397704437646, 
34.0730142208428, 52.6692789725701, 37.0430760514208, 36.7443355910977, 
35.8982566656235, 40.6412424451136, 35.2744862221918, 54.678548982798, 
38.2859652829177, 37.882092289331, 36.9443249322792, 41.8082930203149, 
36.3864879283979, 56.4620503647978, 39.423721981151, 39.08356429068, 
38.1457969336282, 43.3953852278697, 37.6794778895487, 58.4713203750257, 
40.6251939825, 40.3765542518308, 39.3472689349772, 44.6883751890205, 
38.9724678506994, 60.4805903852536, 42.047230753089, 41.7292606501079, 
40.6402588961279, 45.9813651501713, 40.3945046212885, 62.4898603954815, 
43.6343229606438, 43.0819670483851, 41.7288785332687, 47.8740996142097, 
41.7472110195657, 64.2733617774813, 44.987029358921, NA, 42.9717677647656, 
49.2961363847987, 43.0402009807164, 66.4065758881114, 46.0990310651272, 
NA, 44.0837694709717, 50.5891263459495, 44.2830902122133, 68.1900772701113, 
47.5210678357162, NA, 45.3266587024686, 51.8821163071003, 45.8701824197681, 
69.9735786521111, 48.6881184109175, NA, 46.4937092776699, 53.3825140276639, 
47.2228888180453, 71.6551505013311, 49.9310076424144)), .Names = c("Games", 
"League", "Lower", "Prediction", "Upper"), class = "data.frame", row.names = c(NA, 
228L))

0 个答案:

没有答案