I would like to change the proportion of the graph covered by the "zoom". If we look at the following image we are at a ratio "graph:zoom" around 1:2 I would like instead a ratio 2:1. In other words, what I want is to reduce the height of the zoom. How should I proceed?
Here is my code
require(dplyr)
require(tidyverse)
require(ggforce)
HY <- DebitH %>%
ggplot(aes(x = Date, y = Débit_horaire)) +
geom_point(alpha = 6/10, size = 0.3, color = "blue") +
geom_line(alpha = 4/10, size = 0.5, color = "blue") +
labs(x = "Date", y = "Débit Horaire (m3/s)")+
theme_bw() +
theme(panel.grid.major.y = element_line(color = "grey",
size = 0.25,
linetype = 2),
legend.position = "none") +
facet_zoom(xlim = as.POSIXct(c("2021-01-15 00:00:00","2021-02-15 00:00:00")))
And here you will find a sample of the data
DebitH <-
structure(list(Date = structure(c(1610233200, 1610236800, 1610240400,
1610244000, 1610247600, 1610251200, 1610254800, 1610258400, 1610262000,
1610265600, 1610269200, 1610272800, 1610276400, 1610280000, 1610283600,
1610287200, 1610290800, 1610294400, 1610298000, 1610301600, 1610305200,
1610308800, 1610312400, 1610316000, 1610319600, 1610323200, 1610326800,
1610330400, 1610334000, 1610337600, 1610341200, 1610344800, 1610348400,
1610352000, 1610355600, 1610359200, 1610362800, 1610366400, 1610370000,
1610373600, 1610377200, 1610380800, 1610384400, 1610388000, 1610391600,
1610395200, 1610398800, 1610402400, 1610406000, 1610409600, 1610413200,
1610416800, 1610420400, 1610424000, 1610427600, 1610431200, 1610434800,
1610438400, 1610442000, 1610445600, 1610449200, 1610452800, 1610456400,
1610460000, 1610463600, 1610467200, 1610470800, 1610474400, 1610478000,
1610481600, 1610485200, 1610488800, 1610492400, 1610496000, 1610499600,
1610503200, 1610506800, 1610510400, 1610514000, 1610517600, 1610521200,
1610524800, 1610528400, 1610532000, 1610535600, 1610539200, 1610542800,
1610546400, 1610550000, 1610553600, 1610557200, 1610560800, 1610564400,
1610568000, 1610571600, 1610575200, 1610578800, 1610582400, 1610586000,
1610589600, 1610593200, 1610596800, 1610600400, 1610604000, 1610607600,
1610611200, 1610614800, 1610618400, 1610622000, 1610625600, 1610629200,
1610632800, 1610636400, 1610640000, 1610643600, 1610647200, 1610650800,
1610654400, 1610658000, 1610661600, 1610665200, 1610668800, 1610672400,
1610676000, 1610679600, 1610683200, 1610686800, 1610690400, 1610694000,
1610697600, 1610701200, 1610704800, 1610708400, 1610712000, 1610715600,
1610719200, 1610722800, 1610726400, 1610730000, 1610733600, 1610737200,
1610740800, 1610744400, 1610748000, 1610751600, 1610755200, 1610758800,
1610762400, 1610766000, 1610769600, 1610773200, 1610776800, 1610780400,
1610784000, 1610787600, 1610791200, 1610794800, 1610798400, 1610802000,
1610805600, 1610809200, 1610812800, 1610816400, 1610820000, 1610823600,
1610827200, 1610830800, 1610834400, 1610838000, 1610841600, 1610845200,
1610848800, 1610852400, 1610856000, 1610859600, 1610863200, 1610866800,
1610870400, 1610874000, 1610877600, 1610881200, 1610884800, 1610888400,
1610892000, 1610895600, 1610899200, 1610902800, 1610906400, 1610910000,
1610913600, 1610917200, 1610920800, 1610924400, 1610928000, 1610931600,
1610935200, 1610938800, 1610942400, 1610946000, 1610949600, 1610953200,
1610956800, 1610960400, 1610964000, 1610967600, 1610971200, 1610974800,
1610978400, 1610982000, 1610985600, 1610989200, 1610992800, 1610996400,
1.611e+09, 1611003600, 1611007200, 1611010800, 1611014400, 1611018000,
1611021600, 1611025200, 1611028800, 1611032400, 1611036000, 1611039600,
1611043200, 1611046800, 1611050400, 1611054000, 1611057600, 1611061200,
1611064800, 1611068400, 1611072000, 1611075600, 1611079200, 1611082800,
1611086400, 1611090000, 1611093600, 1611097200, 1611100800, 1611104400,
1611108000, 1611111600, 1611115200, 1611118800, 1611122400, 1611126000,
1611129600, 1611133200, 1611136800, 1611140400, 1611144000, 1611147600,
1611151200, 1611154800, 1611158400, 1611162000, 1611165600, 1611169200,
1611172800, 1611176400, 1611180000, 1611183600, 1611187200, 1611190800,
1611194400, 1611198000, 1611201600, 1611205200, 1611208800, 1611212400,
1611216000, 1611219600, 1611223200, 1611226800, 1611230400, 1611234000,
1611237600, 1611241200, 1611244800, 1611248400, 1611252000, 1611255600,
1611259200, 1611262800, 1611266400, 1611270000, 1611273600, 1611277200,
1611280800, 1611284400, 1611288000, 1611291600, 1611295200, 1611298800,
1611302400, 1611306000, 1611309600, 1611313200, 1611316800, 1611320400,
1611324000, 1611327600, 1611331200, 1611334800, 1611338400, 1611342000,
1611345600, 1611349200, 1611352800, 1611356400, 1611360000, 1611363600,
1611367200, 1611370800, 1611374400, 1611378000, 1611381600, 1611385200,
1611388800, 1611392400, 1611396000, 1611399600, 1611403200, 1611406800,
1611410400, 1611414000, 1611417600, 1611421200, 1611424800, 1611428400,
1611432000, 1611435600, 1611439200, 1611442800, 1611446400, 1611450000,
1611453600, 1611457200, 1611460800, 1611464400, 1611468000, 1611471600,
1611475200, 1611478800, 1611482400, 1611486000, 1611489600, 1611493200,
1611496800, 1611500400, 1611504000, 1611507600, 1611511200, 1611514800,
1611518400, 1611522000, 1611525600, 1611529200, 1611532800, 1611536400,
1611540000, 1611543600, 1611547200, 1611550800, 1611554400, 1611558000,
1611561600, 1611565200, 1611568800, 1611572400, 1611576000, 1611579600,
1611583200, 1611586800, 1611590400, 1611594000, 1611597600, 1611601200,
1611604800, 1611608400, 1611612000, 1611615600, 1611619200, 1611622800,
1611626400, 1611630000, 1611633600, 1611637200, 1611640800, 1611644400,
1611648000, 1611651600, 1611655200, 1611658800, 1611662400, 1611666000,
1611669600, 1611673200, 1611676800, 1611680400, 1611684000, 1611687600,
1611691200, 1611694800, 1611698400, 1611702000, 1611705600, 1611709200,
1611712800, 1611716400, 1611720000, 1611723600, 1611727200, 1611730800,
1611734400, 1611738000, 1611741600, 1611745200, 1611748800, 1611752400,
1611756000, 1611759600, 1611763200, 1611766800, 1611770400, 1611774000,
1611777600, 1611781200, 1611784800, 1611788400, 1611792000, 1611795600,
1611799200, 1611802800, 1611806400, 1611810000, 1611813600, 1611817200,
1611820800, 1611824400, 1611828000, 1611831600, 1611835200, 1611838800,
1611842400, 1611846000, 1611849600, 1611853200, 1611856800, 1611860400,
1611864000, 1611867600, 1611871200, 1611874800, 1611878400, 1611882000,
1611885600, 1611889200, 1611892800, 1611896400, 1611900000, 1611903600,
1611907200, 1611910800, 1611914400, 1611918000, 1611921600, 1611925200,
1611928800, 1611932400, 1611936000, 1611939600, 1611943200, 1611946800,
1611950400, 1611954000, 1611957600, 1611961200, 1611964800, 1611968400,
1611972000, 1611975600, 1611979200, 1611982800, 1611986400, 1611990000,
1611993600, 1611997200, 1612000800, 1612004400, 1612008000, 1612011600,
1612015200, 1612018800, 1612022400, 1612026000, 1612029600, 1612033200,
1612036800, 1612040400, 1612044000, 1612047600, 1612051200, 1612054800,
1612058400, 1612062000, 1612065600, 1612069200, 1612072800, 1612076400,
1612080000, 1612083600, 1612087200, 1612090800, 1612094400, 1612098000,
1612101600, 1612105200, 1612108800, 1612112400, 1612116000, 1612119600,
1612123200, 1612126800, 1612130400, 1612134000, 1612137600, 1612141200,
1612144800, 1612148400, 1612152000, 1612155600, 1612159200, 1612162800,
1612166400, 1612170000, 1612173600, 1612177200, 1612180800, 1612184400,
1612188000, 1612191600, 1612195200, 1612198800, 1612202400, 1612206000,
1612209600, 1612213200, 1612216800, 1612220400, 1612224000, 1612227600,
1612231200, 1612234800, 1612238400, 1612242000, 1612245600, 1612249200,
1612252800, 1612256400, 1612260000, 1612263600, 1612267200, 1612270800,
1612274400, 1612278000, 1612281600, 1612285200, 1612288800, 1612292400,
1612296000, 1612299600, 1612303200, 1612306800, 1612310400, 1612314000,
1612317600, 1612321200, 1612324800, 1612328400, 1612332000, 1612335600,
1612339200, 1612342800, 1612346400, 1612350000, 1612353600, 1612357200,
1612360800, 1612364400, 1612368000, 1612371600, 1612375200, 1612378800,
1612382400, 1612386000, 1612389600, 1612393200, 1612396800, 1612400400,
1612404000, 1612407600, 1612411200, 1612414800, 1612418400, 1612422000,
1612425600, 1612429200, 1612432800, 1612436400, 1612440000, 1612443600,
1612447200, 1612450800, 1612454400, 1612458000, 1612461600, 1612465200,
1612468800, 1612472400, 1612476000, 1612479600, 1612483200, 1612486800,
1612490400, 1612494000, 1612497600, 1612501200, 1612504800, 1612508400,
1612512000, 1612515600, 1612519200, 1612522800, 1612526400, 1612530000,
1612533600, 1612537200, 1612540800, 1612544400, 1612548000, 1612551600,
1612555200, 1612558800, 1612562400, 1612566000, 1612569600, 1612573200,
1612576800, 1612580400, 1612584000, 1612587600, 1612591200, 1612594800,
1612598400, 1612602000, 1612605600, 1612609200, 1612612800, 1612616400,
1612620000, 1612623600, 1612627200, 1612630800, 1612634400, 1612638000,
1612641600, 1612645200, 1612648800, 1612652400, 1612656000, 1612659600,
1612663200, 1612666800, 1612670400, 1612674000, 1612677600, 1612681200,
1612684800, 1612688400, 1612692000, 1612695600, 1612699200, 1612702800,
1612706400, 1612710000, 1612713600, 1612717200, 1612720800, 1612724400,
1612728000, 1612731600, 1612735200, 1612738800, 1612742400, 1612746000,
1612749600, 1612753200, 1612756800, 1612760400, 1612764000, 1612767600,
1612771200, 1612774800, 1612778400, 1612782000, 1612785600, 1612789200,
1612792800, 1612796400, 1612800000, 1612803600, 1612807200, 1612810800,
1612814400, 1612818000, 1612821600, 1612825200, 1612828800, 1612832400,
1612836000, 1612839600, 1612843200, 1612846800, 1612850400, 1612854000,
1612857600, 1612861200, 1612864800, 1612868400, 1612872000, 1612875600,
1612879200, 1612882800, 1612886400, 1612890000, 1612893600, 1612897200,
1612900800, 1612904400, 1612908000, 1612911600, 1612915200, 1612918800,
1612922400, 1612926000, 1612929600, 1612933200, 1612936800, 1612940400,
1612944000, 1612947600, 1612951200, 1612954800, 1612958400, 1612962000,
1612965600, 1612969200, 1612972800, 1612976400, 1612980000, 1612983600,
1612987200, 1612990800, 1612994400, 1612998000, 1613001600, 1613005200,
1613008800, 1613012400, 1613016000, 1613019600, 1613023200, 1613026800,
1613030400, 1613034000, 1613037600, 1613041200, 1613044800, 1613048400,
1613052000, 1613055600, 1613059200, 1613062800, 1613066400, 1613070000,
1613073600, 1613077200, 1613080800, 1613084400, 1613088000, 1613091600,
1613095200, 1613098800, 1613102400, 1613106000, 1613109600, 1613113200,
1613116800, 1613120400, 1613124000, 1613127600, 1613131200, 1613134800,
1613138400, 1613142000, 1613145600, 1613149200, 1613152800, 1613156400,
1613160000, 1613163600, 1613167200, 1613170800, 1613174400, 1613178000,
1613181600, 1613185200, 1613188800, 1613192400, 1613196000, 1613199600,
1613203200, 1613206800, 1613210400, 1613214000, 1613217600, 1613221200,
1613224800, 1613228400, 1613232000, 1613235600, 1613239200, 1613242800,
1613246400, 1613250000, 1613253600, 1613257200, 1613260800, 1613264400,
1613268000, 1613271600, 1613275200, 1613278800, 1613282400, 1613286000,
1613289600, 1613293200, 1613296800, 1613300400, 1613304000, 1613307600,
1613311200, 1613314800, 1613318400, 1613322000, 1613325600, 1613329200,
1613332800, 1613336400, 1613340000, 1613343600, 1613347200, 1613350800,
1613354400, 1613358000, 1613361600, 1613365200, 1613368800, 1613372400,
1613376000, 1613379600, 1613383200, 1613386800, 1613390400, 1613394000,
1613397600, 1613401200, 1613404800, 1613408400, 1613412000, 1613415600,
1613419200, 1613422800, 1613426400, 1613430000, 1613433600, 1613437200,
1613440800, 1613444400, 1613448000, 1613451600, 1613455200, 1613458800,
1613462400, 1613466000, 1613469600, 1613473200, 1613476800, 1613480400,
1613484000, 1613487600, 1613491200, 1613494800, 1613498400, 1613502000,
1613505600, 1613509200, 1613512800, 1613516400, 1613520000, 1613523600,
1613527200, 1613530800, 1613534400, 1613538000, 1613541600, 1613545200,
1613548800, 1613552400, 1613556000, 1613559600, 1613563200, 1613566800,
1613570400, 1613574000, 1613577600, 1613581200, 1613584800, 1613588400,
1613592000, 1613595600, 1613599200, 1613602800, 1613606400, 1613610000,
1613613600, 1613617200, 1613620800, 1613624400, 1613628000, 1613631600,
1613635200, 1613638800, 1613642400, 1613646000, 1613649600, 1613653200,
1613656800, 1613660400, 1613664000, 1613667600, 1613671200, 1613674800,
1613678400, 1613682000, 1613685600, 1613689200, 1613692800, 1613696400,
1613700000, 1613703600, 1613707200, 1613710800, 1613714400, 1613718000,
1613721600, 1613725200, 1613728800, 1613732400, 1613736000, 1613739600,
1613743200, 1613746800, 1613750400, 1613754000, 1613757600, 1613761200,
1613764800, 1613768400, 1613772000, 1613775600, 1613779200, 1613782800,
1613786400, 1613790000, 1613793600, 1613797200, 1613800800, 1613804400,
1613808000, 1613811600, 1613815200, 1613818800, 1613822400, 1613826000,
1613829600, 1613833200, 1613836800, 1613840400, 1613844000, 1613847600,
1613851200, 1613854800, 1613858400, 1613862000, 1613865600, 1613869200,
1613872800, 1613876400, 1613880000, 1613883600, 1613887200, 1613890800,
1613894400, 1613898000, 1613901600, 1613905200, 1613908800, 1613912400,
1613916000, 1613919600, 1613923200, 1613926800, 1613930400, 1613934000,
1613937600, 1613941200, 1613944800, 1613948400, 1613952000, 1613955600,
1613959200, 1613962800, 1613966400, 1613970000, 1613973600, 1613977200,
1613980800, 1613984400, 1613988000, 1613991600, 1613995200, 1613998800,
1614002400, 1614006000, 1614009600, 1614013200, 1614016800, 1614020400,
1614024000, 1614027600, 1614031200, 1614034800, 1614038400, 1614042000,
1614045600, 1614049200, 1614052800, 1614056400, 1614060000, 1614063600,
1614067200, 1614070800, 1614074400, 1614078000, 1614081600, 1614085200,
1614088800, 1614092400, 1614096000, 1614099600, 1614103200, 1614106800,
1614110400, 1614114000, 1614117600, 1614121200, 1614124800, 1614128400,
1614132000, 1614135600, 1614139200, 1614142800, 1614146400, 1614150000,
1614153600, 1614157200, 1614160800, 1614164400, 1614168000, 1614171600,
1614175200, 1614178800, 1614182400, 1614186000, 1614189600, 1614193200,
1614196800, 1614200400, 1614204000, 1614207600, 1614211200, 1614214800,
1614218400, 1614222000, 1614225600, 1614229200, 1614232800, 1614236400,
1614240000, 1614243600, 1614247200, 1614250800, 1614254400, 1614258000,
1614261600, 1614265200, 1614268800, 1614272400, 1614276000, 1614279600,
1614283200, 1614286800, 1614290400, 1614294000, 1614297600, 1614301200,
1614304800, 1614308400, 1614312000, 1614315600, 1614319200, 1614322800,
1614326400, 1614330000, 1614333600, 1614337200, 1614340800, 1614344400,
1614348000, 1614351600, 1614355200, 1614358800, 1614362400, 1614366000,
1614369600, 1614373200, 1614376800, 1614380400, 1614384000, 1614387600,
1614391200, 1614394800, 1614398400, 1614402000, 1614405600, 1614409200,
1614412800, 1614416400, 1614420000, 1614423600, 1614427200, 1614430800,
1614434400, 1614438000, 1614441600, 1614445200, 1614448800, 1614452400,
1614456000, 1614459600, 1614463200, 1614466800, 1614470400, 1614474000,
1614477600, 1614481200, 1614484800, 1614488400, 1614492000, 1614495600,
1614499200, 1614502800, 1614506400, 1614510000, 1614513600, 1614517200,
1614520800, 1614524400, 1614528000, 1614531600, 1614535200, 1614538800,
1614542400, 1614546000, 1614549600, 1614553200, 1614556800, 1614560400,
1614564000, 1614567600, 1614571200, 1614574800, 1614578400, 1614582000,
1614585600, 1614589200, 1614592800, 1614596400, 1614600000, 1614603600,
1614607200, 1614610800, 1614614400, 1614618000, 1614621600, 1614625200,
1614628800, 1614632400, 1614636000, 1614639600, 1614643200, 1614646800,
1614650400, 1614654000, 1614657600, 1614661200, 1614664800, 1614668400,
1614672000, 1614675600, 1614679200, 1614682800, 1614686400, 1614690000,
1614693600, 1614697200, 1614700800, 1614704400, 1614708000, 1614711600,
1614715200, 1614718800, 1614722400, 1614726000, 1614729600, 1614733200,
1614736800, 1614740400, 1614744000, 1614747600, 1614751200, 1614754800,
1614758400, 1614762000, 1614765600, 1614769200, 1614772800, 1614776400,
1614780000, 1614783600, 1614787200, 1614790800, 1614794400, 1614798000,
1614801600, 1614805200, 1614808800, 1614812400, 1614816000, 1614819600,
1614823200, 1614826800, 1614830400, 1614834000, 1614837600, 1614841200,
1614844800, 1614848400, 1614852000, 1614855600, 1614859200, 1614862800,
1614866400, 1614870000, 1614873600, 1614877200, 1614880800, 1614884400,
1614888000, 1614891600, 1614895200, 1614898800), tzone = "UTC", class = c("POSIXct",
"POSIXt")), Débit_horaire = c(5.052, 5.036, 5.009, 4.982, 4.958,
4.937, 4.917, 4.885, 4.858, 4.834, 4.804, 4.786, 4.769, 4.753,
4.741, 4.722, 4.713, 4.702, 4.689, 4.68, 4.669, 4.664, 4.658,
4.645, 4.623, 4.595, 4.567, 4.539, 4.51, 4.48, 4.443, 4.413,
4.381, 4.352, 4.327, 4.318, 4.291, 4.27, 4.268, 4.268, 4.265,
4.257, 4.254, 4.258, 4.27, 4.283, 4.295, 4.299, 4.303, 4.307,
4.305, 4.308, 4.32, 4.334, 4.355, 4.396, 4.457, 4.531, 4.624,
4.738, 4.879, 5.057, 5.28, 5.558, 5.863, 6.186, 6.562, 6.958,
7.327, 7.555, 7.638, 7.638, 7.577, 7.452, 7.291, 7.089, 6.867,
6.646, 6.469, 6.301, 6.161, 6.043, 5.946, 5.872, 5.807, 5.752,
5.702, 5.67, 5.658, 5.65, 5.647, 5.656, 5.692, 5.74, 5.786, 5.839,
5.91, 6.003, 6.124, 6.256, 6.374, 6.489, 6.596, 6.686, 6.72,
6.725, 6.706, 6.684, 6.646, 6.61, 6.578, 6.568, 6.554, 6.54,
6.529, 6.535, 6.538, 6.542, 6.553, 6.531, 6.547, 6.54, 6.534,
6.51, 6.504, 6.486, 6.462, 6.444, 6.429, 6.412, 6.395, 6.373,
6.365, 6.354, 6.344, 6.334, 6.326, 6.315, 6.303, 6.295, 6.295,
6.298, 6.296, 6.298, 6.289, 6.273, 6.258, 6.238, 6.225, 6.219,
6.21, 6.213, 6.216, 6.216, 6.22, 6.222, 6.229, 6.233, 6.236,
6.239, 6.238, 6.248, 6.258, 6.271, 6.292, 6.311, 6.33, 6.342,
6.348, 6.358, 6.36, 6.365, 6.366, 6.359, 6.353, 6.342, 6.333,
6.327, 6.33, 6.327, 6.319, 6.326, 6.332, 6.324, 6.34, 6.356,
6.373, 6.402, 6.443, 6.487, 6.537, 6.571, 6.582, 6.582, 6.563,
6.54, 6.515, 6.478, 6.442, 6.41, 6.372, 6.331, 6.304, 6.277,
6.246, 6.218, 6.205, 6.199, 6.193, 6.186, 6.187, 6.203, 6.233,
6.274, 6.315, 6.362, 6.4, 6.432, 6.459, 6.484, 6.512, 6.539,
6.544, 6.548, 6.543, 6.529, 6.525, 6.593, 6.638, 6.713, 6.831,
6.968, 7.142, 7.37, 7.656, 7.924, 8.117, 8.181, 8.262, 8.273,
8.25, 8.243, 8.183, 8.13, 8.073, 8.021, 7.953, 7.888, 7.819,
7.765, 7.733, 7.703, 7.675, 7.663, 7.661, 7.673, 7.701, 7.739,
7.8, 7.843, 7.902, 7.973, 8.06, 8.136, 8.216, 8.342, 8.429, 8.585,
8.694, 8.838, 9.026, 9.38, 9.815, 10.294, 10.786, 11.347, 11.859,
12.233, 12.637, 12.966, 13.283, 13.685, 13.908, 14.334, 14.721,
15.149, 15.581, 16.521, 17.244, 17.842, 18.501, 19.313, 20.18,
20.831, 21.707, 22.559, 23.352, 24.222, 25.223, 25.933, 26.78,
27.336, 28.231, 28.845, 29.255, 29.805, 30.559, 30.458, 30.79,
30.01, 30.098, 29.579, 29.405, 29.149, 28.992, 28.879, 28.596,
28.513, 27.866, 27.839, 27.721, 27.259, 27.385, 26.951, 26.759,
26.467, 26.188, 25.971, 25.564, 25.572, 25.392, 25.243, 25.029,
24.91, 24.723, 24.44, 24.286, 24.039, 23.907, 23.594, 23.454,
23.31, 23.152, 22.881, 22.773, 22.481, 22.202, 21.956, 21.718,
21.385, 21.212, 20.804, 20.526, 20.251, 19.879, 19.599, 19.357,
19.033, 18.914, 18.647, 18.546, 18.301, 18.163, 17.975, 17.763,
17.563, 17.43, 17.19, 17.061, 16.821, 16.673, 16.518, 16.312,
16.137, 16.007, 15.833, 15.698, 15.528, 15.349, 15.195, 15.025,
14.867, 14.718, 14.57, 14.357, 14.224, 14.021, 13.917, 13.79,
13.584, 13.405, 13.267, 13.115, 13, 12.925, 12.786, 12.678, 12.518,
12.44, 12.342, 12.221, 12.138, 12.006, 11.919, 11.84, 11.776,
11.701, 11.605, 11.54, 11.484, 11.371, 11.321, 11.252, 11.177,
11.123, 11.066, 11.028, 10.961, 10.917, 10.842, 10.808, 10.706,
10.66, 10.588, 10.534, 10.496, 10.439, 10.434, 10.407, 10.393,
10.326, 10.289, 10.243, 10.188, 10.134, 10.09, 10.07, 10.039,
10.089, 10.19, 10.407, 10.695, 11.179, 11.769, 12.402, 13.126,
13.95, 14.598, 15.244, 15.748, 16.186, 16.655, 16.938, 17.177,
17.321, 17.365, 17.337, 17.256, 17.256, 17.163, 17.1, 17.143,
17.363, 17.495, 17.883, 18.542, 19.075, 19.628, 20.129, 20.61,
20.944, 21.508, 22.023, 22.557, 23.16, 23.827, 24.4, 24.849,
25.24, 25.387, 25.282, 25.309, 25.296, 25.562, 25.898, 26, 26.274,
26.225, 26.295, 26.394, 26.274, 26.071, 26.072, 26.035, 26.211,
26.383, 26.303, 26.501, 26.474, 26.513, 26.728, 26.825, 27.036,
27.121, 27.443, 27.65, 27.775, 27.689, 27.79, 28.197, 27.82,
28.144, 27.998, 27.789, 27.686, 26.934, 26.954, 26.612, 26.222,
26.192, 25.722, 25.616, 25.531, 25.292, 25.189, 24.797, 24.832,
24.664, 24.525, 24.343, 24.419, 24.284, 24.044, 24.054, 23.818,
23.651, 23.619, 23.587, 23.589, 23.397, 23.314, 23.144, 22.834,
22.846, 22.571, 22.437, 22.204, 22.036, 21.734, 21.588, 21.283,
21.018, 20.798, 20.394, 20.138, 19.926, 19.679, 19.477, 19.19,
18.914, 18.683, 18.514, 18.243, 18.11, 17.981, 17.873, 17.723,
17.655, 17.56, 17.496, 17.444, 17.353, 17.342, 17.289, 17.221,
17.182, 17.05, 16.966, 16.87, 16.649, 16.514, 16.457, 16.305,
16.172, 16.121, 16.223, 16.198, 16.412, 16.695, 16.984, 17.443,
17.808, 18.403, 19.015, 19.509, 19.919, 20.47, 20.922, 21.258,
21.561, 21.636, 21.557, 21.321, 21.223, 20.979, 20.834, 20.559,
20.501, 20.434, 20.312, 20.226, 20.08, 19.971, 19.846, 19.8,
19.712, 19.652, 19.59, 19.502, 19.442, 19.378, 19.261, 19.197,
19.193, 19.159, 19.119, 19.053, 18.966, 18.916, 18.877, 18.774,
18.71, 18.623, 18.501, 18.422, 18.277, 18.145, 18.057, 17.947,
17.828, 17.73, 17.56, 17.472, 17.347, 17.187, 17.019, 16.896,
16.784, 16.676, 16.496, 16.395, 16.255, 16.154, 16.125, 16.037,
15.981, 15.889, 15.897, 15.811, 15.786, 15.723, 15.584, 15.535,
15.433, 15.333, 15.291, 15.213, 15.091, 15.02, 14.928, 14.845,
14.804, 14.916, 15.406, 15.627, 16, 16.414, 16.809, 17.147, 17.457,
17.723, 17.973, 18.175, 18.371, 18.551, 18.613, 18.581, 18.389,
18.036, 17.58, 17.179, 16.751, 16.425, 16.129, 15.928, 15.791,
15.61, 15.487, 15.389, 15.363, 15.355, 15.312, 15.326, 15.301,
15.324, 15.291, 15.266, 15.184, 15.102, 15.056, 15.008, 14.947,
14.899, 14.84, 14.82, 14.819, 14.781, 14.766, 14.768, 14.715,
14.696, 14.631, 14.54, 14.455, 14.344, 14.209, 14.103, 14.027,
13.931, 13.848, 13.769, 13.662, 13.611, 13.493, 13.424, 13.358,
13.286, 13.232, 13.132, 13.034, 12.98, 12.937, 12.86, 12.76,
12.694, 12.604, 12.561, 12.466, 12.361, 12.257, 12.138, 12.025,
11.95, 11.863, 11.767, 11.675, 11.554, 11.473, 11.38, 11.287,
11.198, 11.125, 11.074, 11.007, 10.96, 10.906, 10.85, 10.768,
10.693, 10.62, 10.513, 10.435, 10.33, 10.226, 10.147, 10.045,
9.956, 9.844, 9.758, 9.669, 9.596, 9.542, 9.488, 9.453, 9.423,
9.359, 9.331, 9.332, 9.307, 9.279, 9.242, 9.204, 9.147, 9.079,
8.982, 8.892, 8.814, 8.74, 8.659, 8.602, 8.531, 8.45, 8.412,
8.35, 8.284, 8.243, 8.202, 8.168, 8.133, 8.111, 8.08, 8.062,
8.044, 8.024, 8.007, 7.975, 7.924, 7.867, 7.782, 7.71, 7.624,
7.544, 7.463, 7.373, 7.297, 7.233, 7.166, 7.103, 7.052, 7.024,
6.985, 6.938, 6.917, 6.914, 6.909, 6.893, 6.9, 6.903, 6.917,
6.891, 6.853, 6.803, 6.749, 6.694, 6.639, 6.565, 6.483, 6.42,
6.37, 6.32, 6.282, 6.252, 6.226, 6.204, 6.214, 6.215, 6.166,
6.155, 6.134, 6.133, 6.158, 6.175, 6.181, 6.175, 6.167, 6.148,
6.116, 6.082, 6.046, 6.019, 5.983, 5.962, 5.933, 5.912, 5.891,
5.864, 5.85, 5.831, 5.822, 5.806, 5.806, 5.813, 5.828, 5.856,
5.876, 5.907, 5.931, 5.97, 6.023, 6.055, 6.072, 6.069, 6.06,
6.052, 6.028, 6.015, 5.987, 5.965, 5.937, 5.902, 5.869, 5.836,
5.798, 5.77, 5.756, 5.767, 5.812, 5.869, 5.935, 6.029, 6.119,
6.188, 6.235, 6.292, 6.332, 6.383, 6.455, 6.575, 6.634, 6.617,
6.543, 6.441, 6.336, 6.241, 6.162, 6.08, 6.011, 5.942, 5.885,
5.83, 5.785, 5.756, 5.729, 5.691, 5.666, 5.628, 5.581, 5.531,
5.478, 5.431, 5.383, 5.327, 5.278, 5.23, 5.193, 5.159, 5.119,
5.086, 5.057, 5.034, 5.016, 4.995, 4.912, 4.963, 4.987, 5.019,
5.099, 5.21, 5.313, 5.476, 5.692, 5.883, 6.152, 6.457, 6.633,
6.623, 6.445, 6.218, 5.996, 5.813, 5.667, 5.548, 5.461, 5.379,
5.303, 5.24, 5.168, 5.122, 5.078, 5.044, 5.004, 4.973, 4.943,
4.911, 4.875, 4.848, 4.823, 4.794, 4.772, 4.75, 4.727, 4.711,
4.693, 4.668, 4.652, 4.639, 4.627, 4.617, 4.608, 4.593, 4.573,
4.56, 4.549, 4.544, 4.541, 4.532, 4.512, 4.504, 4.493, 4.474,
4.465, 4.45, 4.438, 4.417, 4.407, 4.396, 4.387, 4.381, 4.375,
4.361, 4.351, 4.337, 4.334, 4.33, 4.325, 4.32, 4.311, 4.312,
4.305, 4.291, 4.274, 4.257, 4.248, 4.233, 4.23, 4.222, 4.216,
4.215, 4.2, 4.19, 4.184, 4.177, 4.172, 4.161, 4.152, 4.145, 4.141,
4.136, 4.133, 4.126, 4.114, 4.099, 4.087, 4.078, 4.064, 4.05,
4.043, 4.035, 4.025, 4.013, 4.002, 3.989, 3.979, 3.97, 3.966,
3.958, 3.943, 3.94, 3.932, 3.928, 3.918, 3.91, 3.901, 3.88, 3.874,
3.866, 3.849, 3.831, 3.818, 3.804, 3.795, 3.787, 3.781, 3.779,
3.773, 3.767, 3.763, 3.757, 3.754, 3.751, 3.745, 3.738, 3.729,
3.731, 3.724, 3.723, 3.72, 3.72, 3.709, 3.707, 3.709, 3.707,
3.685, 3.668, 3.667, 3.682, 3.671, 3.652, 3.644, 3.635, 3.632,
3.626, 3.617, 3.614, 3.604, 3.598, 3.591, 3.586, 3.58, 3.578,
3.57, 3.564, 3.558, 3.547, 3.534, 3.524, 3.514, 3.499, 3.481,
3.476, 3.459, 3.449, 3.44, 3.43, 3.414, 3.41, 3.411, 3.417, 3.431,
3.455, 3.496, 3.53, 3.568, 3.604, 3.645, 3.685, 3.717, 3.728,
3.727, 3.69, 3.635, 3.592, 3.558, 3.52, 3.498, 3.472, 3.44, 3.413,
3.393, 3.37, 3.353, 3.321, 3.287, 3.261, 3.24, 3.237, 3.23, 3.227,
3.225, 3.223, 3.233, 3.242, 3.247, 3.234, 3.208, 3.181, 3.154,
3.134, 3.123, 3.109, 3.097, 3.091, 3.091, 3.085, 3.08, 3.074,
3.073, 3.07, 3.046, 3.052, 3.053, 3.049, 3.046, 3.029, 3.028,
3.018, 3.003, 2.997, 2.981, 2.971, 2.957, 2.946, 2.937, 2.931,
2.926, 2.916, 2.907, 2.904, 2.893, 2.887, 2.876, 2.866, 2.861,
2.854, 2.851, 2.85, 2.855, 2.865, 2.86, 2.859, 2.855, 2.843,
2.838, 2.828, 2.806, 2.793, 2.782, 2.775, 2.77, 2.759, 2.752,
2.744, 2.737, 2.729, 2.723, 2.719, 2.711, 2.703, 2.693, 2.697,
2.7, 2.699, 2.695, 2.693, 2.693, 2.692, 2.69, 2.681, 2.67, 2.658,
2.642, 2.637, 2.63, 2.623, 2.614, 2.611, 2.604, 2.604, 2.598,
2.591, 2.593, 2.594, 2.591, 2.585, 2.602, 2.601, 2.597, 2.59,
2.583, 2.582, 2.569, 2.562, 2.551, 2.544, 2.536, 2.537, 2.523,
2.516, 2.513, 2.515, 2.516, 2.516, 2.519, 2.518, 2.517, 2.516,
2.52, 2.534, 2.566, 2.607, 2.625, 2.675, 2.703, 2.742, 2.782,
2.827, 2.956)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA,
-1297L))
You could set the size of the zoom panel relative to the main plot via the argument zoom.size which defaults to 2, i.e. the zoom panel is twice the size of the main panel. Hence, to achieve your desired result set zoom.size=.5:
require(dplyr)
require(tidyverse)
require(ggforce)
DebitH %>%
ggplot(aes(x = Date, y = Débit_horaire)) +
geom_point(alpha = 6 / 10, size = 0.3, color = "blue") +
geom_line(alpha = 4 / 10, size = 0.5, color = "blue") +
labs(x = "Date", y = "Débit Horaire (m3/s)") +
theme_bw() +
theme(
panel.grid.major.y = element_line(
color = "grey",
size = 0.25,
linetype = 2
),
legend.position = "none"
) +
facet_zoom(xlim = as.POSIXct(c("2021-01-15 00:00:00", "2021-02-15 00:00:00")), zoom.size = .5)
I am conducting some regression analysis and I need to first create a Bartik Instrument to use as an IV. Essentially, I have 10 decile groups of the income distribution. These are both at a global level and a country level (as there is an unbalanced panel of countries in the dataset). I want to grow each country's decile groups according to worldwide changes.
The image above represents the world and shows the percentage of people in each income decile on the left-hand side. On the right are the calculated percentage changes for each income decile between years. There are 10 columns all up for the 10 deciles.
The image below shows the country's decile groups. The starting year will be 1990 for each country (ie, the beginning decile proportion for each decile will be the year 1990 for each country. This serves as the "weight" in all of the statistics). Then, each decile will grow at the same percentage change as the global level.
For example, if dp1 is 1.92 in 1990 for the country Afghanistan, 1991 will be calculated from the global percentage change between 1990 and 1991. Because the global change was -2.857%, the predicted value of dp1 in 1991 for Afghanistan will be 1.865. This value will then be used in the calculation for predicting 1992.
The issue is, it needs to start at 1990 for each country and end in the final predicted year of 2019. I cannot just use a mutate function as it won't recognize that each country restarts in 1990.
Any guidance on this issue will be greatly appreciated. Please let me know if you need to see any more of the data as it is all open source and can therefore be freely shared.
Dput of the world data frame:
structure(list(Entity = c("World", "World", "World", "World",
"World", "World", "World", "World", "World", "World", "World",
"World", "World", "World", "World", "World", "World", "World",
"World", "World", "World", "World", "World", "World", "World",
"World", "World", "World", "World", "World", "World"), Year = c(1990,
1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012,
2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020), Code = c("WLD",
"WLD", "WLD", "WLD", "WLD", "WLD", "WLD", "WLD", "WLD", "WLD",
"WLD", "WLD", "WLD", "WLD", "WLD", "WLD", "WLD", "WLD", "WLD",
"WLD", "WLD", "WLD", "WLD", "WLD", "WLD", "WLD", "WLD", "WLD",
"WLD", "WLD", "WLD"), gini = c("69.95", "70.18", "70.07", "69.88",
"69.79", "69.51", "69.16", "68.93", "68.98", "68.83", "68.76",
"68.43", "68.1", "67.68", "67.24", "66.79", "66.22", "65.57",
"64.9", "63.8", "63.28", "62.92", "62.54", "62.11", "61.68",
"61.47", "61.12", "60.92", "60.81", "60.65", "60.6"), palma = c(14.44,
14.74, 14.2, 13.7, 13.28, 12.95, 12.46, 12.31, 12.12, 12.04,
12.12, 11.74, 11.49, 11.18, 10.91, 10.55, 10.08, 9.67, 9.27,
8.53, 8.29, 8.12, 7.91, 7.74, 7.47, 7.36, 7.25, 7.11, 7.07, 6.95,
6.97), dp1 = c(0.35, 0.34, 0.35, 0.36, 0.36, 0.38, 0.38, 0.38,
0.39, 0.38, 0.38, 0.39, 0.38, 0.38, 0.39, 0.39, 0.4, 0.4, 0.4,
0.43, 0.43, 0.43, 0.43, 0.43, 0.45, 0.45, 0.44, 0.43, 0.44, 0.44,
0.43), dp2 = c(0.71, 0.72, 0.76, 0.78, 0.82, 0.82, 0.84, 0.86,
0.87, 0.9, 0.88, 0.89, 0.9, 0.92, 0.93, 0.93, 0.95, 0.98, 1.01,
1.07, 1.09, 1.1, 1.1, 1.14, 1.14, 1.14, 1.17, 1.19, 1.18, 1.19,
1.2), dp3 = c(1.09, 1.06, 1.1, 1.18, 1.19, 1.25, 1.29, 1.31,
1.3, 1.33, 1.31, 1.36, 1.38, 1.39, 1.43, 1.48, 1.5, 1.54, 1.59,
1.69, 1.72, 1.74, 1.79, 1.81, 1.83, 1.88, 1.89, 1.88, 1.94, 1.95,
1.94), dp4 = c(1.52, 1.5, 1.59, 1.64, 1.74, 1.75, 1.82, 1.82,
1.9, 1.89, 1.88, 1.93, 1.97, 2, 2.02, 2.07, 2.18, 2.24, 2.29,
2.44, 2.48, 2.51, 2.57, 2.58, 2.71, 2.72, 2.73, 2.82, 2.76, 2.81,
2.8), dp5 = c(2.11, 2.15, 2.27, 2.34, 2.42, 2.51, 2.53, 2.56,
2.6, 2.64, 2.7, 2.72, 2.74, 2.8, 2.92, 2.99, 3.05, 3.1, 3.2,
3.44, 3.52, 3.57, 3.65, 3.77, 3.76, 3.86, 3.93, 3.96, 3.95, 4.03,
4.04), dp6 = c(3.23, 3.18, 3.25, 3.38, 3.44, 3.52, 3.6, 3.64,
3.66, 3.74, 3.68, 3.87, 3.98, 4.08, 4.07, 4.14, 4.35, 4.54, 4.68,
4.85, 5.02, 5.11, 5.2, 5.29, 5.48, 5.43, 5.54, 5.56, 5.62, 5.6,
5.57), dp7 = c(5.49, 5.42, 5.43, 5.42, 5.37, 5.41, 5.5, 5.66,
5.49, 5.57, 5.67, 5.73, 5.86, 6.03, 6.23, 6.23, 6.49, 6.63, 6.91,
7.12, 7.37, 7.38, 7.59, 7.72, 7.84, 7.94, 7.92, 8.02, 8, 8.05,
8.13), dp8 = c(10.96, 10.76, 10.3, 10.04, 9.78, 9.73, 9.78, 9.82,
9.67, 9.61, 9.7, 9.75, 9.73, 10, 10.18, 10.5, 10.55, 10.88, 11.04,
11.32, 11.4, 11.63, 11.62, 11.72, 11.78, 11.82, 12.05, 11.85,
12.1, 12.08, 12.12), dp9 = c(21.51, 21.26, 20.81, 20.53, 20.22,
20.17, 20.15, 20.03, 19.9, 19.75, 19.77, 19.7, 19.88, 19.72,
19.74, 19.75, 19.69, 19.71, 19.75, 19.51, 19.48, 19.49, 19.39,
19.36, 19.23, 19.14, 19.05, 19.37, 19.25, 19.3, 19.38), dp10 = c(52.93,
53.51, 54.05, 54.24, 54.58, 54.39, 54.02, 53.85, 54.14, 54.13,
53.96, 53.6, 53.13, 52.61, 52.04, 51.45, 50.77, 49.93, 49.08,
48.07, 47.44, 46.98, 46.61, 46.14, 45.75, 45.56, 45.23, 44.9,
44.72, 44.52, 44.37), `dp1_PChangeFrom-1` = c(NA, -0.0285714285714284,
0.0294117647058822, 0.0285714285714286, 0, 0.0555555555555556,
0, 0, 0.0263157894736842, -0.0256410256410257, 0, 0.0263157894736842,
-0.0256410256410257, 0, 0.0263157894736842, 0, 0.0256410256410257,
0, 0, 0.0749999999999999, 0, 0, 0, 0, 0.0465116279069768, 0,
-0.0222222222222222, -0.0227272727272727, 0.0232558139534884,
0, -0.0227272727272727), `dp2_PChangeFrom-1` = c(NA, 0.0140845070422535,
0.0555555555555556, 0.0263157894736842, 0.0512820512820512, 0,
0.024390243902439, 0.0238095238095238, 0.0116279069767442, 0.0344827586206897,
-0.0222222222222222, 0.0113636363636364, 0.0112359550561798,
0.0222222222222222, 0.0108695652173913, 0, 0.0215053763440859,
0.0315789473684211, 0.0306122448979592, 0.0594059405940595, 0.0186915887850467,
0.00917431192660551, 0, 0.0363636363636362, 0, 0, 0.0263157894736842,
0.0170940170940171, -0.00840336134453782, 0.00847457627118645,
0.00840336134453782), `dp3_PChangeFrom-1` = c(NA, -0.0275229357798165,
0.0377358490566038, 0.0727272727272726, 0.00847457627118645,
0.0504201680672269, 0.032, 0.0155038759689923, -0.00763358778625955,
0.0230769230769231, -0.0150375939849624, 0.0381679389312977,
0.014705882352941, 0.00724637681159421, 0.0287769784172662, 0.034965034965035,
0.0135135135135135, 0.0266666666666667, 0.0324675324675325, 0.0628930817610062,
0.0177514792899408, 0.0116279069767442, 0.0287356321839081, 0.0111731843575419,
0.0110497237569061, 0.0273224043715846, 0.00531914893617022,
-0.0052910052910053, 0.0319148936170213, 0.00515463917525774,
-0.00512820512820513), `dp4_PChangeFrom-1` = c(NA, -0.0131578947368421,
0.0600000000000001, 0.031446540880503, 0.0609756097560976, 0.00574712643678161,
0.04, 0, 0.0439560439560439, -0.00526315789473685, -0.0052910052910053,
0.0265957446808511, 0.0207253886010363, 0.0152284263959391, 0.01,
0.0247524752475247, 0.0531400966183576, 0.0275229357798165, 0.0223214285714285,
0.0655021834061135, 0.0163934426229508, 0.0120967741935483, 0.0239043824701195,
0.00389105058365768, 0.0503875968992248, 0.00369003690036909,
0.00367647058823522, 0.0329670329670329, -0.0212765957446809,
0.0181159420289856, -0.00355871886121005), `dp5_PChangeFrom-1` = c(NA,
0.018957345971564, 0.0558139534883721, 0.0308370044052863, 0.0341880341880342,
0.037190082644628, 0.00796812749003985, 0.0118577075098815, 0.015625,
0.0153846153846154, 0.0227272727272727, 0.00740740740740741,
0.00735294117647059, 0.021897810218978, 0.0428571428571429, 0.0239726027397261,
0.0200668896321069, 0.0163934426229509, 0.0322580645161291, 0.0749999999999999,
0.0232558139534884, 0.0142045454545454, 0.0224089635854342, 0.0328767123287672,
-0.00265251989389927, 0.0265957446808511, 0.0181347150259068,
0.00763358778625949, -0.00252525252525247, 0.020253164556962,
0.00248138957816372), `dp6_PChangeFrom-1` = c(NA, -0.0154798761609907,
0.0220125786163522, 0.04, 0.0177514792899408, 0.0232558139534884,
0.0227272727272727, 0.0111111111111111, 0.0054945054945055, 0.0218579234972678,
-0.0160427807486631, 0.0516304347826087, 0.0284237726098191,
0.0251256281407035, -0.00245098039215681, 0.017199017199017,
0.0507246376811594, 0.0436781609195403, 0.0308370044052863, 0.0363247863247863,
0.0350515463917526, 0.0179282868525898, 0.0176125244618395, 0.0173076923076923,
0.0359168241965974, -0.00912408759124101, 0.0202578268876612,
0.00361010830324902, 0.0107913669064749, -0.00355871886121005,
-0.00535714285714274), `dp7_PChangeFrom-1` = c(NA, -0.0127504553734062,
0.00184501845018446, -0.00184162062615097, -0.00922509225092248,
0.00744878957169461, 0.0166358595194085, 0.0290909090909091,
-0.0300353356890459, 0.0145719489981785, 0.0179533213644524,
0.0105820105820107, 0.0226876090750436, 0.0290102389078498, 0.033167495854063,
0, 0.0417335473515248, 0.0215716486902927, 0.0422322775263952,
0.0303907380607815, 0.0351123595505618, 0.00135685210312073,
0.0284552845528455, 0.0171277997364954, 0.0155440414507772, 0.0127551020408164,
-0.00251889168765749, 0.0126262626262626, -0.00249376558603486,
0.00625000000000009, 0.00993788819875777), `dp8_PChangeFrom-1` = c(NA,
-0.0182481751824818, -0.0427509293680297, -0.0252427184466021,
-0.0258964143426295, -0.0051124744376277, 0.00513874614594028,
0.00408997955010234, -0.0152749490835031, -0.00620475698035165,
0.00936524453694067, 0.00515463917525781, -0.00205128205128201,
0.0277492291880781, 0.018, 0.031434184675835, 0.00476190476190483,
0.0312796208530806, 0.014705882352941, 0.0253623188405798, 0.00706713780918729,
0.0201754385964913, -0.00085984522785912, 0.00860585197934608,
0.00511945392491457, 0.00339558573853998, 0.0194585448392555,
-0.0165975103734441, 0.0210970464135021, -0.00165289256198344,
0.00331125827814562), `dp9_PChangeFrom-1` = c(NA, -0.0116225011622501,
-0.0211665098777047, -0.0134550696780393, -0.015099853872382,
-0.00247279920870411, -0.000991571641051221, -0.00595533498759293,
-0.00649026460309548, -0.00753768844221098, 0.00101265822784808,
-0.0035407182599899, 0.00913705583756344, -0.00804828973843059,
0.00101419878296144, 0.000506585612968671, -0.00303797468354424,
0.00101574403250379, 0.00202942668696089, -0.0121518987341771,
-0.00153767298821123, 0.000513347022587167, -0.00513083632632108,
-0.0015471892728211, -0.0067148760330578, -0.00468018720748829,
-0.00470219435736676, 0.0167979002624672, -0.0061951471347445,
0.00259740259740263, 0.00414507772020717), `dp10_PChangeFrom-1` = c(NA,
0.0109578688834309, 0.0100915716688469, 0.00351526364477345,
0.00626843657817102, -0.00348112861854155, -0.00680272108843533,
-0.00314698259903743, 0.00538532961931289, -0.000184706316956003,
-0.00314058747459822, -0.00667160859896218, -0.00876865671641789,
-0.00978731413514028, -0.0108344421212697, -0.011337432744043,
-0.0132167152575316, -0.0165452038605476, -0.0170238333667134,
-0.0205786471067644, -0.0131058872477637, -0.00969645868465432,
-0.00787569178373771, -0.0100836730315383, -0.00845253576072823,
-0.00415300546448082, -0.00724319578577712, -0.00729604244970149,
-0.00400890868596881, -0.00447227191413228, -0.00336927223719689
)), row.names = c(NA, -31L), class = "data.frame")
dput of the countries data frame::
structure(list(Year = numeric(0), Entity = character(0), Code = character(0),
gini = character(0), palma = numeric(0), dp1 = numeric(0),
dp2 = numeric(0), dp3 = numeric(0), dp4 = numeric(0), dp5 = numeric(0),
dp6 = numeric(0), dp7 = numeric(0), dp8 = numeric(0), dp9 = numeric(0),
dp10 = numeric(0)), class = c("grouped_df", "tbl_df", "tbl",
"data.frame"), row.names = integer(0), groups = structure(list(
Entity = character(0), Year = numeric(0), .rows = structure(list(), ptype = integer(0), class = c("vctrs_list_of",
"vctrs_vctr", "list"))), row.names = integer(0), class = c("tbl_df",
"tbl", "data.frame"), .drop = TRUE))
I have data with several data agregations (Year, Quarter, Month).
I try to leave a space between each Date aggregation in x-axis label.
I obtain this for the moment :
And I want to obtain :
Here my data :
My dataframe (dput) :
r8_plot = structure(list(DATE = c(2016L, 2017L, 2018L, 201701L, 201702L,
201703L, 201704L, 201801L, 201802L, 201803L, 201804L, 201801L,
201802L, 201803L, 201804L, 201805L, 201806L, 201807L, 201808L,
201809L, 201810L, 201811L, 201812L, 201844L, 201845L, 201846L,
201847L, 201848L, 201849L, 201850L), Var1 = c(6.64, 6.21, 6.53,
6.31, 6.01, 6.36, 6.17, 6.76, 6.37, 6.68, 6.27, 7.5, 6.49, 6.4,
6.54, 6.18, 6.37, 5.98, 6.37, 7.48, 6.6, 5.97, 6.25, 5.42, 6.18,
5.81, 6.46, 6.36, 6.05, 6.35), Var2 = c(2.38, 2.25, 2.36, 2.22,
2.52, 1.98, 2.27, 2.44, 2.31, 2.27, 2.41, 2.53, 2.25, 2.51, 2.35,
2.42, 2.19, 2.51, 1.91, 2.38, 2.34, 2.29, 2.68, 2.15, 1.89, 2.6,
2.52, 2.37, 2.97, 2.71), Var3 = c(4.26, 3.96, 4.17, 4.09, 3.5,
4.38, 3.9, 4.32, 4.06, 4.4, 3.86, 4.96, 4.23, 3.9, 4.19, 3.77,
4.18, 3.47, 4.46, 5.1, 4.26, 3.68, 3.57, 3.27, 4.29, 3.2, 3.95,
3.99, 3.09, 3.64), Var4 = c(35.84, 36.17, 36.08, 35.2, 41.86,
31.17, 36.76, 36.07, 36.27, 34.07, 38.43, 33.78, 34.76, 39.18,
35.95, 39.07, 34.35, 42.04, 29.91, 31.8, 35.48, 38.38, 42.86,
39.72, 30.53, 44.85, 38.94, 37.24, 48.98, 42.63), Var5 = c("Y",
"Y", "Y", "Q", "Q", "Q", "Q", "Q", "Q", "Q", "Q", "M", "M", "M",
"M", "M", "M", "M", "M", "M", "M", "M", "M", "W", "W", "W", "W",
"W", "W", "W"), Var6 = structure(1:30, .Label = c("2016", "2017",
"2018", "Q1-2017", "Q2-2017", "Q3-2017", "Q4-2017", "Q1-2018",
"Q2-2018", "Q3-2018", "Q4-2018", "M01-2018", "M02-2018", "M03-2018",
"M04-2018", "M05-2018", "M06-2018", "M07-2018", "M08-2018", "M09-2018",
"M10-2018", "M11-2018", "M12-2018", "W44-2018", "W45-2018", "W46-2018",
"W47-2018", "W48-2018", "W49-2018", "W50-2018"), class = "factor"),
Var7 = c(7.1, 6.7, 6.7, 6.7, 6.7, 6.6, 6.6, 6.7, 6.7, 6.6,
6.6, 6.7, 6.7, 6.7, 6.7, 6.7, 6.6, 6.6, 6.6, 6.6, 6.6, 6.6,
6.6, 6.6, 6.6, 6.6, 6.6, 6.6, 6.6, 6.6)), .Names = c("DATE",
"Var1", "Var2", "Var3", "Var4", "Var5", "Var6", "Var7"), row.names = c(NA,
30L), class = "data.frame")
r8_plot$Var6 = factor(r8_plot$Var6, labels = unique(r8_plot$Var6), levels=unique(r8_plot$Var6))
library(plotly)
r8_plot %>% plot_ly(x = ~Var6) %>%
add_bars(y = ~Var1,marker = list(color = '#00802b'),
name = "Var1") %>%
add_bars(y = ~Var2,marker = list(color = '#ff9933'),
name = "Var2")%>%
add_lines(y = ~Var4,
name = "Var4",
yaxis = "y2", line = list(color = '#1a1aff'))%>%
add_lines(y = ~Var7,
name = "Var7",
yaxis = "y1")%>%
layout(barmode = "stack",
yaxis2 = list(overlaying = "y",side = "right"),barmode = "stack",xaxis = list(title = 'DATE'), yaxis = list(title = 'All quantity'), title ="Chart") %>% layout(height = 750, width = 1000, hovermode = 'closest',margin = list(b = 115))
Thanks in advance
You can add NaN y-values to any data frame and Plotly will interrupt the plot at this position.
For example
library(plotly)
data = data.frame(list(x = c(1, 2, NaN, 3, 4),
y = c(1, 2, NaN, 3, 4)))
plot_ly(data, x = ~x) %>%
add_lines(y = ~y)
will give you
For more complex data, like in the question, a function introducing the empty rows might be easier than doing it manually.
split_by_date <- function(data) {
data_length <- length(data[,1])
index <- 0
new_data <- data
new_line <- list(replicate(length(data), NaN))
for (i in 2:length(data$DATE)) {
if (substr(toString(data$Var6[[i]]), 1, 1) != substr(toString(data$Var6[[i - 1]]), 1, 1)) {
new_data <- rbind.data.frame(new_data[1:i + index - 1,], new_line[[1]], data[i:data_length,])
new_data$Var6[[index + i]] <- paste(replicate(index + 1, " "), collapse = " ")
index <- index + 1
rownames(new_data) <- 1:as.integer(data_length + index)
}
}
return(new_data)
}
We just need to make sure that the x-value is always unique, i.e. simply concatenate an increasing number of spaces. Otherwise we'll just get a single break in the graph.
Also another row x is introduced to help with plotting the x-values in the correct order.
r8_plot = structure(list(DATE = c(2016L, 2017L, 2018L, 201701L, 201702L, 201703L, 201704L, 201801L, 201802L, 201803L, 201804L, 201801L, 201802L, 201803L, 201804L, 201805L, 201806L, 201807L, 201808L, 201809L, 201810L, 201811L, 201812L, 201844L, 201845L, 201846L, 201847L, 201848L, 201849L, 201850L),
Var1 = c(6.64, 6.21, 6.53, 6.31, 6.01, 6.36, 6.17, 6.76, 6.37, 6.68, 6.27, 7.5, 6.49, 6.4, 6.54, 6.18, 6.37, 5.98, 6.37, 7.48, 6.6, 5.97, 6.25, 5.42, 6.18, 5.81, 6.46, 6.36, 6.05, 6.35),
Var2 = c(2.38, 2.25, 2.36, 2.22, 2.52, 1.98, 2.27, 2.44, 2.31, 2.27, 2.41, 2.53, 2.25, 2.51, 2.35, 2.42, 2.19, 2.51, 1.91, 2.38, 2.34, 2.29, 2.68, 2.15, 1.89, 2.6, 2.52, 2.37, 2.97, 2.71),
Var3 = c(4.26, 3.96, 4.17, 4.09, 3.5, 4.38, 3.9, 4.32, 4.06, 4.4, 3.86, 4.96, 4.23, 3.9, 4.19, 3.77, 4.18, 3.47, 4.46, 5.1, 4.26, 3.68, 3.57, 3.27, 4.29, 3.2, 3.95, 3.99, 3.09, 3.64),
Var4 = c(35.84, 36.17, 36.08, 35.2, 41.86, 31.17, 36.76, 36.07, 36.27, 34.07, 38.43, 33.78, 34.76, 39.18, 35.95, 39.07, 34.35, 42.04, 29.91, 31.8, 35.48, 38.38, 42.86, 39.72, 30.53, 44.85, 38.94, 37.24, 48.98, 42.63),
Var5 = c("Y", "Y", "Y", "Q", "Q", "Q", "Q", "Q", "Q", "Q", "Q", "M", "M", "M", "M", "M", "M", "M", "M", "M", "M", "M", "M", "W", "W", "W", "W", "W", "W", "W"),
Var6 = c("2016", "2017", "2018", "Q1-2017", "Q2-2017", "Q3-2017", "Q4-2017", "Q1-2018", "Q2-2018", "Q3-2018", "Q4-2018", "M01-2018", "M02-2018", "M03-2018","M04-2018", "M05-2018", "M06-2018", "M07-2018", "M08-2018", "M09-2018", "M10-2018", "M11-2018", "M12-2018", "W44-2018", "W45-2018", "W46-2018", "W47-2018", "W48-2018", "W49-2018", "W50-2018"),
Var7 = c(7.1, 6.7, 6.7, 6.7, 6.7, 6.6, 6.6, 6.7, 6.7, 6.6, 6.6, 6.7, 6.7, 6.7, 6.7, 6.7, 6.6, 6.6, 6.6, 6.6, 6.6, 6.6,6.6, 6.6, 6.6, 6.6, 6.6, 6.6, 6.6, 6.6)),
.Names = c("DATE", "Var1", "Var2", "Var3", "Var4", "Var5", "Var6", "Var7"), row.names = c(NA, 30L), class = "data.frame")
plot <- split_by_date(r8_plot)
plot$x <- structure(1:length(plot$Var6), .Label = plot$Var6, class = "factor")
plot %>% plot_ly(x = ~x, height = 750, width = 1000) %>%
add_bars(y = ~Var1,
marker = list(color = '#00802b'),
name = "Var1") %>%
add_bars(y = ~Var2,
marker = list(color = '#ff9933'),
name = "Var2") %>%
add_lines(y = ~Var4,
name = "Var4",
yaxis = "y2",
line = list(color = '#1a1aff')) %>%
add_lines(y = ~Var7,
name = "Var7",
yaxis = "y1") %>%
layout(barmode = "stack",
xaxis = list(title = 'DATE', range = c(-0.1, 10)),
yaxis = list(title = 'All quantity'),
yaxis2 = list(overlaying = "y",
side = "right"),
title ="Chart",
hovermode = 'closest')
I am trying to plot multiple density plots for some data.
I have the following code:
ggplot(data=stack) +
geom_density(aes(x=OfferPrice, group=Country, fill=Country),
alpha=0.5, adjust=2) +
facet_grid(~Country) +
theme_bw()
My problem arises with the x-axis on each of the density plots.
Looking a little closer at the data:
stack %>%
group_by(Country) %>%
summarise(min(OfferPrice),
mean(OfferPrice),
max(OfferPrice))
It looks like Country - JN has some very high numbers. Earlier I cut the top and bottom 5% of extreme values for each group so there shouldn´t necessarily be extreme values. What I think is wrong is the x-axis on the plots are using the maximum from the JN group. How is it possible to have different x-axis depending on each group?
Data:
stack <- structure(list(Country = c("US", "GB", "US", "HK", "JN", "US",
"CH", "CA", "US", "US", "CA", "JN", "GB", "AU", "US", "GB", "US",
"GB", "HK", "CH", "CA", "CA", "US", "GB", "TA", "JN", "CA", "CA",
"CA", "CA", "CH", "GB", "CA", "HK", "CA", "US", "US", "CA", "US",
"AU", "CA", "CA", "CA", "US", "GB", "GB", "AU", "US", "US", "AU",
"CA", "CA", "CA", "US", "CA", "GB", "CA", "US", "GB", "US", "AU",
"AU", "US", "CA", "US", "GB", "AU", "CH", "CA", "CA", "GB", "AU",
"AU", "CH", "CA", "AU", "CH", "US", "CH", "TA", "AU", "AU", "GB",
"CH", "HK", "AU", "AU", "CA", "US", "TA", "GB", "US", "AU", "US",
"CA", "CA", "US", "AU", "CA", "US", "CA", "US", "CA", "US", "CA",
"US", "US", "AU", "CA", "AU", "GB", "US", "HK", "AU", "US", "CA",
"JN", "JN", "GB", "JN", "CA", "CA", "AU", "GB", "GB", "US", "US",
"US", "AU", "GB", "CA", "CA", "US", "CH", "GB", "US", "US", "AU",
"GB", "CH", "JN", "CA", "AU", "CA", "US", "US", "AU", "AU", "CA",
"US", "GB", "GB", "US", "US", "CA", "US", "HK", "AU", "US", "GB",
"US", "GB", "GB", "US", "CA", "JN", "CA", "AU", "CA", "CA", "GB",
"CA", "HK", "HK", "US", "CH", "US", "AU", "TA", "US", "CH", "HK",
"AU", "US", "HK", "GB", "AU", "CH", "US", "AU", "US", "CH", "US",
"CH", "CA", "AU", "HK", "CA", "US", "CH", "GB", "CA", "CA", "CA",
"CA", "US", "CA", "CA", "US", "HK", "US", "HK", "AU", "GB", "AU",
"CH", "US", "AU", "CA", "CA", "US", "GB", "AU", "US", "CH", "CA",
"CA", "CA", "US", "AU", "GB", "GB", "CA", "AU", "CA", "AU", "US",
"HK", "AU", "US", "AU", "CA", "US", "US", "US", "CA", "GB", "CA",
"US", "CA", "US", "AU", "CA", "US", "AU", "CH", "GB", "CA", "CA",
"CA", "CA", "HK", "AU", "TA", "AU", "GB", "AU", "CA", "JN", "US",
"CA", "CA", "AU", "US", "US", "GB", "CA", "US", "GB", "US", "CA",
"CA", "CH", "US", "US", "US", "US", "US", "HK", "CH", "CA", "CA",
"CA", "AU", "GB", "CH", "CA", "GB", "CA", "AU"), EffectiveDate = structure(c(17617,
17500, 17556, 17596, 17618, 17667, 17786, 17728, 17569, 17760,
17585, 17613, 17806, 17847, 17786, 17665, 17702, 17683, 17574,
17725, 17723, 17658, 17563, 17847, 17584, 17578, 17842, 17522,
17697, 17521, 17680, 17794, 17813, 17697, 17773, 17578, 17556,
17595, 17669, 17501, 17655, 17562, 17668, 17589, 17582, 17780,
17812, 17667, 17611, 17758, 17751, 17617, 17505, 17505, 17725,
17506, 17513, 17541, 17644, 17702, 17828, 17688, 17696, 17519,
17850, 17746, 17779, 17547, 17806, 17701, 17638, 17759, 17786,
17770, 17835, 17750, 17841, 17653, 17788, 17553, 17794, 17654,
17724, 17675, 17802, 17638, 17625, 17514, 17709, 17758, 17681,
17507, 17708, 17758, 17800, 17569, 17821, 17493, 17834, 17848,
17639, 17549, 17590, 17575, 17630, 17639, 17760, 17724, 17701,
17725, 17756, 17794, 17511, 17494, 17822, 17758, 17709, 17492,
17605, 17709, 17602, 17644, 17814, 17696, 17760, 17603, 17730,
17675, 17590, 17724, 17743, 17680, 17690, 17711, 17560, 17570,
17702, 17512, 17626, 17618, 17576, 17731, 17527, 17709, 17729,
17672, 17515, 17527, 17641, 17597, 17812, 17540, 17602, 17743,
17662, 17709, 17505, 17737, 17603, 17515, 17568, 17843, 17738,
17508, 17816, 17578, 17590, 17812, 17743, 17528, 17616, 17687,
17646, 17515, 17816, 17557, 17507, 17564, 17777, 17802, 17511,
17842, 17584, 17556, 17547, 17844, 17590, 17674, 17759, 17583,
17836, 17721, 17724, 17801, 17578, 17808, 17682, 17849, 17708,
17515, 17746, 17633, 17759, 17591, 17802, 17540, 17560, 17588,
17800, 17787, 17821, 17724, 17645, 17527, 17722, 17556, 17704,
17844, 17619, 17792, 17577, 17637, 17843, 17765, 17688, 17562,
17834, 17738, 17653, 17645, 17718, 17676, 17637, 17570, 17490,
17534, 17646, 17625, 17766, 17808, 17675, 17786, 17808, 17555,
17739, 17802, 17617, 17619, 17667, 17634, 17662, 17711, 17806,
17513, 17627, 17673, 17574, 17647, 17609, 17619, 17521, 17543,
17686, 17807, 17613, 17543, 17543, 17528, 17694, 17576, 17584,
17521, 17605, 17618, 17723, 17641, 17683, 17823, 17634, 17844,
17836, 17816, 17539, 17583, 17618, 17687, 17589, 17602, 17717,
17535, 17718, 17625, 17822, 17651, 17521, 17751, 17617, 17563,
17578, 17772), class = "Date"), OfferPrice = c(44, 13, 33, 0.3,
3000, 23, 6.26, 0.35, 10, 6.25, 0.25, 7110, 109.5, 0.11, 16,
2, 5.5, 15, 0.5, 8.5, 0.5, 0.2, 5, 92.5, 22, 103740, 0.23, 0.75,
8.65, 1.23, 17.4, 1.5, 0.38, 0.84, 8.1, 27.5, 10, 1, 14, 0.42,
0.1, 1.82, 2, 39.8, 238, 340, 0.3, 4.5, 41.5, 0.2, 0.25, 0.27,
0.35, 5, 0.3, 115, 0.15, 5, 142.25, 14, 2.43, 0.02, 24, 0.115,
8.25, 25, 0.155, 9.6, 0.67, 6, 52.5, 0.2, 0.2, 1.37, 1.6, 0.65,
2.9, 4, 7, 72, 0.025, 0.14, 22.5, 6.75, 0.64, 0.8, 0.8, 0.4,
22, 94.8, 15, 10, 2.45, 34, 1, 9.3, 6.25, 0.018, 0.2, 24.5, 0.3,
2.9, 0.35, 2.05, 0.4, 29.5, 2.26, 0.36, 0.75, 0.027, 2.8, 16,
3.54, 0.018, 10, 0.15, 1780, 1602, 120, 3900, 0.25, 0.18, 2.32,
269, 175, 18, 18, 23, 0.2, 10, 0.1, 0.6, 4.8, 6, 164.5, 7, 26.42,
0.02, 190, 11, 992, 0.2, 1.42, 0.55, 23, 33.5, 0.35, 0.065, 1.16,
29.5, 65, 8, 27.5, 18.9, 0.15, 17, 0.63, 0.34, 26.25, 0.65, 6.9,
10, 6.75, 1.21, 0.95, 73125, 2.5961, 0.054, 1.2, 9.64, 251, 2.46,
0.18, 0.375, 9.97, 20.43, 25.5, 0.025, 60, 3, 1.55, 0.5, 0.2,
17, 0.443, 8, 0.05, 5.25, 1.15, 0.45, 7.155, 17, 24.5, 12.5,
2.1, 0.75, 0.35, 0.39, 38.2, 0.63, 16, 0.15, 0.1, 0.12, 2.32,
10, 0.3, 1.66, 17, 0.4, 1.3, 0.3, 1.08, 30, 0.8, 10.88, 0.9,
0.21, 0.17, 1.7, 2.25, 1, 0.08, 1.5, 14.75, 0.35, 0.44, 0.35,
17, 2, 37, 195, 0.165, 0.02, 0.2, 0.015, 25, 1.09, 0.45, 10,
0.145, 0.92, 36, 13.25, 4, 0.6, 101, 0.7, 15, 0.3, 0.7, 0.06,
0.25, 6.5, 1.1, 16.72, 1.25, 0.1, 0.12, 0.28, 1.18, 0.4, 0.02,
75, 0.08, 5, 0.02, 0.5, 2878, 8, 0.15, 0.33, 0.1, 21.25, 1, 12,
5.83, 4.25, 1.65, 3.15, 3, 0.15, 7.4, 31.25, 12, 24, 19.75, 41.5,
0.88, 13.65, 0.25, 0.15, 0.25, 2.35, 101, 1.26, 1.65, 10, 1.32,
0.5)), row.names = c(NA, -300L), class = c("tbl_df", "tbl", "data.frame"
))
You can specify whether you want free scales (x, y or both) in facet_grid.
ggplot(data=stack) +
geom_density(aes(x=OfferPrice, group=Country, fill=Country),
alpha=0.5, adjust=2) +
facet_grid(~Country, scales = "free_x") +
theme_bw()