Serious difference between rAmChart and naive R Plot - r

I have observed very serious difference between rAmCharts plot and ordinary R Plot as below :
My data
dat = structure(list(x = c(-100, -99.61, -99.22, -98.83, -98.43, -98.04,
-97.65, -97.26, -96.87, -96.48, -96.09, -95.69, -95.3, -94.91,
-94.52, -94.13, -93.74, -93.35, -92.95, -92.56, -92.17, -91.78,
-91.39, -90, -90.61, -90.22, -89.82, -89.43, -89.04, -88.65,
-88.26, -87.87, -87.48, -87.08, -86.69, -86.3, -85.91, -85.52,
-85.13, -84.74, -84.34, -83.95, -83.56, -83.17, -82.78, -82.39,
-81, -81.6, -81.21, -80.82, -80.43, -80.04, -79.65, -79.26, -78.86,
-78.47, -78.08, -77.69, -77.3, -76.91, -76.52, -76.13, -75.73,
-75.34, -74.95, -74.56, -74.17, -73.78, -73.39, -72.99, -72.6,
-72.21, -71.82, -71.43, -71.04, -70.65, -70.25, -69.86, -69.47,
-69.08, -68.69, -68.3, -67.91, -67.51, -67.12, -66.73, -66.34,
-65.95, -65.56, -65.17, -64.77, -64.38, -63.99, -63.6, -63.21,
-62.82, -62.43, -62.04, -61.64, -61.25, -60.86, -60.47, -60.08,
-59.69, -59.3, -58.9, -58.51, -58.12, -57.73, -57.34, -56.95,
-56.56, -56.16, -55.77, -55.38, -54.99, -54.6, -54.21, -53.82,
-53.42, -53.03, -52.64, -52.25, -51.86, -51.47, -51.08, -50.68,
-50.29, -49.9, -49.51, -49.12, -48.73, -48.34, -47.95, -47.55,
-47.16, -46.77, -46.38, -45.99, -45.6, -45.21, -44.81, -44.42,
-44.03, -43.64, -43.25, -42.86, -42.47, -42.07, -41.68, -41.29,
-40.9, -40.51, -40.12, -39.73, -39.33, -38.94, -38.55, -38.16,
-37.77, -37.38, -36.99, -36.59, -36.2, -35.81, -35.42, -35.03,
-34.64, -34.25, -33.86, -33.46, -33.07, -32.68, -32.29, -31.9,
-31.51, -31.12, -30.72, -30.33, -29.94, -29.55, -29.16, -28.77,
-28.38, -27.98, -27.59, -27.2, -26.81, -26.42, -26.03, -25.64,
-25.24, -24.85, -24.46, -24.07, -23.68, -23.29, -22.9, -22.5,
-22.3, -22.11, -21.72, -21.33, -20.94, -20.8, -20.55, -20.16,
-19.77, -19.37, -18.98, -18.59, -18.36, -18.2, -18.2, -17.94,
-17.81, -17.5, -17.42, -17.03, -16.63, -16.48, -16.24, -15.99,
-15.85, -15.67, -15.46, -15.07, -14.68, -14.29, -13.89, -13.5,
-13.11, -12.78, -12.72, -12.7, -12.33, -11.94, -11.75, -11.55,
-11.29, -11.25, -11.21, -11.15, -10.96, -10.95, -10.76, -10.37,
-10.35, -10.26, -10.06, -9.98, -9.82, -9.79, -9.64, -9.59, -9.55,
-9.48, -9.35, -9.2, -8.93, -8.93, -8.89, -8.86, -8.81, -8.81,
-8.78, -8.68, -8.61, -8.59, -8.5, -8.5, -8.48, -8.46, -8.44,
-8.41, -8.41, -8.35, -8.24, -8.21, -8.02, -8.01, -8, -7.82, -7.78,
-7.7, -7.63, -7.61, -7.55, -7.49, -7.45, -7.44, -7.43, -7.39,
-7.25, -7.24, -7.23, -7.22, -7.08, -7.06, -7, -6.98, -6.97, -6.95,
-6.93, -6.85, -6.82, -6.82, -6.8, -6.77, -6.74, -6.69, -6.69,
-6.68, -6.64, -6.62, -6.61, -6.55, -6.51, -6.46, -6.45, -6.43,
-6.39, -6.2, -6.17, -6.14, -6.13, -6.13, -6.09, -6.07, -6.06,
-6.04, -5.91, -5.84, -5.82, -5.81, -5.81, -5.79, -5.76, -5.73,
-5.73, -5.73, -5.69, -5.68, -5.66, -5.61, -5.59, -5.56, -5.56,
-5.54, -5.49, -5.48, -5.44, -5.39, -5.37, -5.35, -5.32, -5.28,
-5.25, -5.22, -5.18, -5.15, -5.14, -5.08, -4.98, -4.97, -4.94,
-4.89, -4.89, -4.88, -4.83, -4.82, -4.8, -4.79, -4.78, -4.78,
-4.76, -4.76, -4.75, -4.72, -4.7, -4.65, -4.65, -4.63, -4.63,
-4.6, -4.58, -4.56, -4.52, -4.5, -4.5, -4.48, -4.39, -4.38, -4.36,
-4.35, -4.35, -4.29, -4.27, -4.24, -4.24, -4.22, -4.11, -4.09,
-4.08, -4.07, -4.06, -4.01, -4, -3.97, -3.97, -3.96, -3.94, -3.92,
-3.92, -3.89, -3.87, -3.78, -3.76, -3.74, -3.72, -3.72, -3.66,
-3.63, -3.61, -3.58, -3.55, -3.54, -3.53, -3.51, -3.48, -3.45,
-3.45, -3.42, -3.39, -3.35, -3.33, -3.32, -3.32, -3.32, -3.31,
-3.29, -3.26, -3.25, -3.24, -3.24, -3.18, -3.17, -3.15, -3.13,
-3.12, -3.12, -3.1, -3.08, -3.07, -3.05, -3.04, -3.02, -3.02,
-2, -2.99, -2.99, -2.94, -2.94, -2.93, -2.91, -2.89, -2.87, -2.87,
-2.85, -2.78, -2.78, -2.77, -2.77, -2.72, -2.72, -2.69, -2.66,
-2.65, -2.64, -2.62, -2.59, -2.59, -2.56, -2.54, -2.52, -2.5,
-2.49, -2.48, -2.48, -2.47, -2.44, -2.43, -2.43, -2.4, -2.39,
-2.38, -2.37, -2.33, -2.31, -2.29, -2.25, -2.24, -2.24, -2.24,
-2.18, -2.15, -2.13, -2.13, -2.13, -2.12, -2.11, -2.11, -2.11,
-2.1, -2.08, -2.06, -2.05, -2.04, -2.03, -2.02, -2.01, -1, -1,
-1, -1.96, -1.96, -1.96, -1.92, -1.9, -1.89, -1.89, -1.87, -1.85,
-1.85, -1.84, -1.8, -1.77, -1.77, -1.77, -1.76, -1.75, -1.71,
-1.71, -1.69, -1.67, -1.67, -1.64, -1.64, -1.62, -1.61, -1.61,
-1.6, -1.6, -1.6, -1.6, -1.58, -1.53, -1.52, -1.52, -1.51, -1.51,
-1.5, -1.5, -1.49, -1.46, -1.45, -1.45, -1.42, -1.41, -1.39,
-1.38, -1.37, -1.37, -1.35, -1.35, -1.34, -1.34, -1.32, -1.26,
-1.26, -1.25, -1.24, -1.23, -1.21, -1.2, -1.19, -1.19, -1.18,
-1.18, -1.12, -1.11, -1.08, -1.06, -1.05, -1.03, -1.02, -1.01,
-1.01, 0.99, 0.98), y = c(1.7597036882208e-16, 3.74523809420545e-16,
6.79924138728896e-16, 5.49147548890779e-16, 2.8444302872708e-16,
2.01730936037434e-16, 4.72623693209037e-16, 5.25606872427607e-16,
5.75755789341732e-19, 2.74318552000638e-17, 7.41872388571549e-17,
1.16379243552747e-16, 1.30330176931005e-17, 1.44493324181405e-16,
1.48200512266161e-16, 2.12152823477696e-16, 1.23512766683157e-16,
1.32574841143743e-16, 4.4989064700399e-17, 1.34533164086192e-16,
1.9006081627268e-16, 2.39080196757097e-16, 1.19793582322272e-16,
9.50635502478515e-17, 8.85078754774532e-17, 4.07507372548731e-17,
4.87962996842999e-17, 0, 0, 0, 2.02892803804376e-17, 4.77664676933343e-17,
0, 1.31499591351899e-17, 7.60486578480149e-17, 1.34732404205651e-16,
9.84383117921681e-17, 2.24652146268012e-18, 3.31437566467248e-17,
1.36540032813809e-16, 2.25953576019843e-18, 0, 0, 4.92104796977405e-17,
8.099623943331e-18, 0, 0, 1.68058680233949e-16, 6.11817343303322e-17,
0, 7.32356256580957e-17, 1.11022302462516e-16, 4.49824864436716e-17,
0, 2.35376025518364e-16, 2.36916329000193e-16, 1.56876067466473e-16,
2.76152717298367e-16, 1.79699773609809e-16, 7.12971788226661e-17,
5.55999796122692e-17, 1.17156003547801e-16, 1.21796814022842e-16,
6.93708098703207e-17, 2.83704104610286e-16, 3.17428461074929e-16,
1.82186510295273e-16, 1.82565027831131e-17, 1.70358298315398e-16,
2.00925226771026e-16, 2.18926513598978e-16, 2.50480721582232e-17,
6.59248227028292e-17, 1.96892892698323e-16, 2.46794494653556e-17,
0, 0, 0, 2.397323191816e-17, 8.92821565470295e-18, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 2.88455838264677e-17, 7.0903834176121e-17,
1.5914161580599e-18, 5.43777976183126e-18, 0, 0, 0, 8.01793020909566e-18,
1.2291364865812e-16, 3.91534557759051e-16, 3.3339281324276e-17,
2.6920670063884e-16, 5.12703847636537e-16, 4.10252736291125e-16,
1.67335218413958e-16, 2.36208053218858e-17, 5.19139551821771e-17,
1.6990665717063e-16, 1.05671649235152e-16, 7.87822176087936e-17,
1.31251504649561e-16, 1.12727132108941e-16, 3.55500613269496e-17,
0, 2.94711841144511e-16, 4.71230498411639e-16, 2.86538537127018e-16,
1.77054704896858e-16, 3.17917488682109e-16, 7.43912492234354e-16,
9.85299115340156e-16, 7.51672782664393e-16, 5.9132409817199e-16,
3.98097952968957e-16, 6.5578603393698e-16, 5.97145485901949e-16,
1.60433998243202e-16, 4.25811910271435e-16, 4.7870409012117e-16,
4.25996607810613e-16, 2.05598457899487e-19, 8.78373073137105e-17,
2.38668937977388e-16, 2.27739609138721e-16, 2.87264175662675e-17,
2.71265894601827e-16, 2.55298436762032e-16, 1.92315140433518e-16,
4.59305282512086e-17, 0, 0, 0, 0, 1.25447724280112e-17, 9.74746480755506e-18,
0, 0, 1.61193874244055e-16, 2.07516793040518e-16, 0, 1.04932676825905e-17,
4.29781195771582e-17, 5.05418409161244e-17, 3.37097279421464e-18,
1.01755688786198e-17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2.39585185015462e-15, 1.00307844757947e-13,
2.78448660159713e-12, 6.05733870945561e-11, 1.04637782728879e-09,
1.44073701738736e-08, 1.58850745566864e-07, 1.41127816790393e-06,
1.01818929340863e-05, 6.01696909626074e-05, 0.000293593157911075,
0.00118947246272509, 0.0040083082842067, 0.0112687308437839,
0.0262927189912457, 0.0498053871221169, 0.0777181016466707, 0.102442967983551,
0.114986839963252, 0.118580121597716, 0.126177132309074, 0.127188782805811,
0.121271820956834, 0.117465483484553, 0.108780200046537, 0.0976939209894227,
0.104149523914498, 0.142645607882759, 0.212686252049453, 0.293612480605814,
0.342210910701918, 0.355155413224826, 0.365154855448977, 0.384819051158378,
0.378154517274975, 0.376509064918937, 0.367722515593318, 0.345362658913025,
0.327076034070167, 0.321727820129925, 0.309516245037894, 0.294803947891027,
0.277545792264962, 0.257889549151338, 0.223616507372753, 0.158476326312876,
0.104669098520124, 0.0824283288525812, 0.100684513213946, 0.155971603197872,
0.236698861779982, 0.311407776596513, 0.332086110342108, 0.333113928406455,
0.440655671266963, 0.567336730000337, 0.63637445909586, 0.7102703824769,
0.809920607861078, 0.825849445050381, 0.842550078559163, 0.861152674706014,
0.938370078905393, 0.941108110137537, 1.02472066702563, 1.22677194585943,
1.22373255169458, 1.27786285801321, 1.42010690766794, 1.49834300218549,
1.61414740995607, 1.64462278104917, 1.78936230867798, 1.84945210274464,
1.87411466011563, 1.9463825982544, 2.08613976834005, 2.2553419669841,
2.54631534493486, 2.5524480071148, 2.59394035381691, 2.62554425369102,
2.68014249846383, 2.67141240872526, 2.70757149824811, 2.81603238909785,
2.8839899688641, 2.90184882278971, 2.9951287820443, 2.99652139700154,
3.01724028758715, 3.03534730166617, 3.0556897358388, 3.07108480003771,
3.08740871482752, 3.1453151227964, 3.25227249128586, 3.27621420636615,
3.46929997872363, 3.47318869267193, 3.48126797055692, 3.67730633718784,
3.7197125935055, 3.80027475958662, 3.90071388567187, 3.90745839492175,
3.97765265132038, 4.04662603771724, 4.10150453224692, 4.10840939509678,
4.11848162897357, 4.17427230709211, 4.35616347869055, 4.3773911786099,
4.37333127319114, 4.39074795131003, 4.57413296670597, 4.5991835145369,
4.67173403660532, 4.70771012631921, 4.71833532297898, 4.73859091510558,
4.7609988834314, 4.87851897030545, 4.90688099592749, 4.90708495949766,
4.94269681072076, 4.97724651284863, 5.01861247231422, 5.0816122115511,
5.08288122580106, 5.09645478789259, 5.14849989788669, 5.1765014973309,
5.18806946280539, 5.26102008301815, 5.31513220867376, 5.37901322965186,
5.39050904937277, 5.41467432648789, 5.46862958191719, 5.70402838742514,
5.74068017503184, 5.7869355981015, 5.79292592322843, 5.79809906089682,
5.84679504928192, 5.87405075516485, 5.88105929301511, 5.9112534644012,
6.08119015734939, 6.16315973447742, 6.18547228033177, 6.2029788813203,
6.20626915953848, 6.23218318922145, 6.26960642805249, 6.30081251375971,
6.30334175165671, 6.30598836813381, 6.35550115668848, 6.37217878250992,
6.39762760751607, 6.46630424712907, 6.48266081704103, 6.5201176295341,
6.53056617507125, 6.54589874311096, 6.61653276370493, 6.62593263262898,
6.67546833550753, 6.73985555239059, 6.77221124359663, 6.79980517064019,
6.83918921144544, 6.87713048798536, 6.92763866766738, 6.95977301066436,
7.01353711451419, 7.06028221091086, 7.0717115945324, 7.14185635363182,
7.2730318576457, 7.28607564938541, 7.32289581246292, 7.38965010818126,
7.39577517563281, 7.40450978843896, 7.4719981715159, 7.48680307301975,
7.51262664110236, 7.52712480348432, 7.5382560820532, 7.53847644359348,
7.56221663623504, 7.56265518809399, 7.57565032702851, 7.60668165263275,
7.63800529332195, 7.70056516841558, 7.70263063282773, 7.73450954917983,
7.73901295061052, 7.77224569243977, 7.80244794623114, 7.8230242472877,
7.88990576584967, 7.92912616458532, 7.91899477452608, 7.93783697777415,
8.07079188787864, 8.08607402868743, 8.11257695782476, 8.12803240275844,
8.13286606685409, 8.21642150157843, 8.24515663469641, 8.30159239085307,
8.3026739892953, 8.32564628010195, 8.5441825420166, 8.53731995330964,
8.5636118706574, 8.57954219394595, 8.60000261083962, 8.69281856402821,
8.69891636496432, 8.74866752381885, 8.75832423422554, 8.78209552768877,
8.8157292790575, 8.84245063132663, 8.85227119925912, 8.90615780503739,
8.93733128458003, 9.12822776206417, 9.16137350978205, 9.19533828269928,
9.24802535874669, 9.2879130233507, 9.37411616202131, 9.44877014946975,
9.47970402875784, 9.5558881475768, 9.61468401105343, 9.63581709000357,
9.67457783743398, 9.70838906470135, 9.77942073015735, 9.85344799782491,
9.85935139960286, 9.92615568316011, 9.99104533257134, 10.0998615305448,
10.173098354516, 10.167178735392, 10.1683760801022, 10.1728419753319,
10.1897428750678, 10.2330374342752, 10.3055994416899, 10.3481776368482,
10.35565504472, 10.3629965495382, 10.5251166230264, 10.5522124316336,
10.5830584906381, 10.6356336313048, 10.6588922173047, 10.6809595148848,
10.7220655484965, 10.7776583022015, 10.7992452102138, 10.8630540268205,
10.8844617554606, 10.9244759193515, 10.9249087038458, 10.9883268932042,
11.0097089543663, 11.0097346241578, 11.1252492688711, 11.1465363027297,
11.1501437235196, 11.2073828938633, 11.2627254111225, 11.3244002008142,
11.3285281334781, 11.3607433381032, 11.5448215655493, 11.5492154944198,
11.5638760696493, 11.5754499839043, 11.6957329062312, 11.7132466623605,
11.7698381257655, 11.8545623483949, 11.8806317388234, 11.8890981384401,
11.9570028739073, 12.0237221695926, 12.0333114872137, 12.1014250352705,
12.0930640441288, 12.1978327722867, 12.2265251283613, 12.2531231238963,
12.2769904479287, 12.2906523656393, 12.2991257148763, 12.3699676292038,
12.3816847947217, 12.3966833191452, 12.4639664222951, 12.4884815352879,
12.4968395998859, 12.5138537174711, 12.5952885497219, 12.6430034996264,
12.6765777170897, 12.7622590902194, 12.7687076739649, 12.7727993658869,
12.7837206146135, 12.8754885410316, 12.8469996815148, 12.9560088492823,
12.9566436411234, 12.9624377506546, 12.9766670002181, 12.9850505491804,
12.9855574265221, 12.9890340483016, 13.0107968127549, 13.0411747523884,
13.0670015731243, 13.0738265725302, 13.0905943751396, 13.1035864740683,
13.1184469209409, 13.1241124605893, 13.1384855640382, 13.140800787323,
13.1408559371454, 13.1753353582809, 13.1800666445606, 13.1838356640309,
13.2159448058419, 13.2337595744097, 13.2444669737106, 13.2453554169858,
13.255254612637, 13.2723568098737, 13.2735311191899, 13.2805103886435,
13.2962997928538, 13.3101767801431, 13.310438133793, 13.3108118677924,
13.2132771863309, 13.3152011787449, 13.3231568502587, 13.3234714687251,
13.324276432583, 13.3239574342302, 13.3238821702482, 13.3203816703585,
13.319685478936, 13.3167971140072, 13.3139101061223, 13.3129451756278,
13.3107139382814, 13.3088823484563, 13.3087236774467, 13.3077988854603,
13.3032458439853, 13.2744479528264, 13.268477049554, 13.2672314189783,
13.2627288615878, 13.2615675531721, 13.2529572332396, 13.2518182569097,
13.2457204237367, 13.217819620186, 13.2121808418273, 13.2071194043963,
13.1747472790749, 13.1722840548772, 13.1452116491842, 13.134543705708,
13.0310721277639, 13.117305936063, 13.0905392509933, 13.0880701934228,
13.0830568146902, 13.0730030443181, 13.0557358249779, 12.9598269042632,
12.9591078315098, 12.9418487176909, 12.9120563995794, 12.8911691983967,
12.8683905110946, 12.8504880667736, 12.8225964838503, 12.8199268803159,
12.8051415856952, 12.8013879059933, 12.6645568170687, 12.6601553773751,
12.5762338009767, 12.5342515954331, 12.5050088385454, 12.4630698111222,
12.4205255859797, 12.4069677138716, 12.3975537517596, 12.3531930414859,
12.3321844078684), z = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L), .Label = "Balloon", class = "factor")), .Names = c("x",
"y", "z"), row.names = c(NA, 600L), class = "data.frame")
rAmCharts plot
library(rAmCharts)
balloonFunction <- htmlwidgets::JS(
'function(item) {',
'if (item.dataContext[\'x\']!=0) { return \'X: \' + item.dataContext[\'x\'] +
\'<br>Y: \' + item.dataContext[\'y\'] +
\'<br>Z: \' + item.dataContext[\'z\'];}',
'}')
p <- amSerialChart(categoryField = "x", precision = 2) %>%
setDataProvider(dataProvider = dat, keepNA = TRUE) %>%
addGraph(valueField = "y", lineColor = "gray", fillAlphas=0.5,
bullet="round", lineThickness=4) %>%
setChartCursor() %>%
setBalloon(cornerRadius=10, color="white",textAlign="left", maxWidth = 1300)
p#graphs[[1]]$balloonFunction <- balloonFunction
p
However, ordinary R plot
plot(x = dat$x, y = dat$y, type = 'l')
As you see, there is serious difference in the view for these 2 different plotting systems.
Any idea how to make rAmCharts close to Ordinary R plot?
Thanks in advance.
PS: I acknowledge Marco Sandri's help to design Balloon in above fashion, and this is integral part of my plot.
Based on Marco's suggestion, below is my Shiny app to implement user defined height for amCharts
ui.R
library(rAmCharts)
library(highcharter)
library(purrr)
fluidPage(
tagList(tags$head(includeCSS("CSS.css"))),
selectInput("Dummy", "Some Dummy number:",c(1,2,3)),
div(amChartsOutput("Plot", height = "1400px"))
)
server.R
server <- function(input, output) {
set.seed(1)
balloonFunction <- htmlwidgets::JS(
'function(item) {',
'if (item.dataContext[\'x\']!=0) {
return \'X: \' + item.dataContext.x +
\'<br>Y: \' + item.dataContext.y +
\'<br>Z: \' + item.dataContext.z;}',
'}')
labFunx <- htmlwidgets::JS(
'function(value) {',
'return value+\'%\';',
'}')
dat = structure(list(x = c(-100, -99.61, -99.22, -98.83, -98.43, -98.04,
-97.65, -97.26, -96.87, -96.48, -96.09, -95.69, -95.3, -94.91,
-94.52, -94.13, -93.74, -93.35, -92.95, -92.56, -92.17, -91.78,
-91.39, -90, -90.61, -90.22, -89.82, -89.43, -89.04, -88.65),
y = c(1.7597036882208e-16, 3.74523809420545e-16, 6.79924138728896e-16,
5.49147548890779e-16, 2.8444302872708e-16, 2.01730936037434e-16,
4.72623693209037e-16, 5.25606872427607e-16, 5.75755789341732e-19,
2.74318552000638e-17, 7.41872388571549e-17, 1.16379243552747e-16,
1.30330176931005e-17, 1.44493324181405e-16, 1.48200512266161e-16,
2.12152823477696e-16, 1.23512766683157e-16, 1.32574841143743e-16,
4.4989064700399e-17, 1.34533164086192e-16, 1.9006081627268e-16,
2.39080196757097e-16, 1.19793582322272e-16, 9.50635502478515e-17,
8.85078754774532e-17, 4.07507372548731e-17, 4.87962996842999e-17,
0, 0, 0), z = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "Balloon", class = "factor")), .Names = c("x",
"y", "z"), row.names = c(NA, 30L), class = "data.frame")
dat <- dat[order(dat$x),]
nr <- nrow(dat)
last.row <- dat[nr,]
last.row$y <- 0
dat <- rbind(dat, last.row)
p <- amXYChart(x=dat$x, y=dat$y) %>%
setDataProvider(dataProvider = dat, keepNA = TRUE) %>%
addGraph(xField = "x", yField = "y", lineColor = "gray", fillAlphas=0.5,
bullet="round", lineThickness=2, bulletColor="transparent") %>%
setChartCursor() %>%
setBalloon(cornerRadius=10, color="black", textAlign="left", maxWidth = 1300)
p#graphs[[1]]$balloonFunction <- balloonFunction
p#valueAxes <- list(list(title='x-axis name', position='bottom',axisAlpha=0.5,
labelFunction=labFunx),
list(title='y-axis name', position='left',axisAlpha=0.5))
output$Plot = renderAmCharts(p)
}
CSS file :
#chartdiv {
width: 100%;
height: 2510px;
margin: 0;
padding: 0;
}

You can try this:
library(rAmCharts)
library(purrr)
balloonFunction <- htmlwidgets::JS(
'function(item) {',
'if (item.dataContext[\'x\']!=0) {
return \'X: \' + item.dataContext.x +
\'<br>Y: \' + item.dataContext.y +
\'<br>Z: \' + item.dataContext.z;}',
'}')
labFunx <- htmlwidgets::JS(
'function(value) {',
'return value+\'%\';',
'}')
dat <- dat[order(dat$x),]
nr <- nrow(dat)
last.row <- dat[nr,]
last.row$y <- 0
dat <- rbind(dat, last.row)
p <- amXYChart(x=dat$x, y=dat$y) %>%
setDataProvider(dataProvider = dat, keepNA = TRUE) %>%
addGraph(xField = "x", yField = "y", lineColor = "gray", fillAlphas=0.5,
bullet="round", lineThickness=2, bulletColor="transparent") %>%
setChartCursor() %>%
setBalloon(cornerRadius=10, color="black", textAlign="left", maxWidth = 1300)
p#graphs[[1]]$balloonFunction <- balloonFunction
p#valueAxes <- list(list(title='x-axis name', position='bottom',axisAlpha=0.5,
labelFunction=labFunx),
list(title='y-axis name', position='left',axisAlpha=0.5))
p

Related

How can i plot a Heatmap in R

Im trying to plot a heatmap in R, but when I run my code it gives me this error:
Error: Can't combine `No.` <integer> and `Mes` <character>.
What I'm doing wrong? Here is my code:
df %>%
pivot_longer(-Localidad) %>%
ggplot(aes(x = name, y = Localidad , fill = value)) +
geom_tile(colour="gray80", size=0.2) +
geom_text(aes(label=value)) +
theme_minimal() +
scale_fill_distiller(palette = "YlGnBu", direction = -1, na.value = "white")
My df its something like this, Im working with a lot of data, so thats why I didnt want to print all the head of, but here it is.
> dput(head(df))
structure(list(No. = 1:6, Mes = c("oct-10", "oct-10", "oct-10",
"oct-10", "oct-10", "oct-10"), Delegacion = c("09CIUDAD DE MÉXICO",
"09CIUDAD DE MÉXICO", "09CIUDAD DE MÉXICO", "09CIUDAD DE MÉXICO",
"09CIUDAD DE MÉXICO", "09CIUDAD DE MÉXICO"), Localidad = c("09016MIGUEL HIDALGO",
"09005GUSTAVO A. MADERO", "09005GUSTAVO A. MADERO", "09003COYOACÁN",
"09010ÁLVARO OBREGÓN", "09011TLÁHUAC"), Esquema = c("U", "U",
"U", "U", "U", "U"), Número = c(629L, 1402L, 699L, 48L, 539L,
55L), Nombre = c("MUNDO DE LOS PEQUES", "GUARDERIA EL ARBOL DE LA NIÑEZ",
"LOS PEQUEÑOS GENIOS II", "MI MUNDO FELIZ", "CENTRO ECOLÓGICO DE DESARROLLO INFANTIL II",
"ESTANCIA INFANTIL TERCER MILENIO"), X2.1 = c(1L, 1L, 1L, 1L,
1L, 1L), X2.2 = c(1L, 1L, 1L, 1L, 1L, 1L), X2.3 = c(1L, 1L, 1L,
1L, 1L, 1L), X2.4 = c(1L, 1L, 1L, 1L, 1L, 1L), X2.5 = c(1L, 1L,
1L, 1L, 1L, 1L), X2.6 = c(1L, 1L, 0L, 1L, 1L, 0L), X2.7 = c(1L,
1L, 1L, 1L, 1L, 1L), X2.8 = c(1L, 1L, 1L, 1L, 1L, 1L), X2.9 = c(1L,
1L, 1L, 1L, 1L, 1L), X2.1.1 = c(1L, 1L, 1L, 1L, 1L, 1L), X2.11 = c(1L,
1L, 1L, 1L, 1L, 1L), X2.12 = c(1L, 1L, 1L, 1L, 1L, 1L), X3.1 = c(1L,
1L, 1L, 1L, 1L, 1L), X3.2 = c(1L, 1L, 1L, 1L, 1L, 1L), X5.1 = c(1L,
1L, 1L, 1L, 1L, 1L), X5.2 = c(1L, 1L, 1L, 1L, 1L, 1L), X5.3 = c(1L,
1L, 1L, 1L, 1L, 1L), X5.4 = c(1L, 1L, 1L, 1L, 1L, 1L), X5.5 = c(1L,
1L, 1L, 1L, 1L, 1L), X5.6 = c(1L, 1L, 1L, 1L, 1L, 1L), X5.7 = c(1L,
1L, 1L, 1L, 1L, 1L), X5.8 = c(1L, 1L, 1L, 1L, 1L, 1L), X6.1 = c(1L,
1L, 1L, 1L, 1L, 1L), X6.2 = c(1L, 1L, 1L, 1L, 1L, 1L), X6.3 = c(1L,
1L, 1L, 1L, 1L, 1L), X6.4 = c(1L, 1L, 1L, 1L, 1L, 1L), X6.5 = c(1L,
1L, 1L, 1L, 1L, 1L), X7.1 = c(1L, 1L, 1L, 1L, 1L, 1L), X7.2 = c(1L,
1L, 1L, 1L, 1L, 1L), X7.3 = c(1L, 1L, 1L, 1L, 1L, 1L), X7.4 = c(1L,
1L, 1L, 1L, 1L, 1L), X8.1 = c(1L, 1L, 1L, 1L, 1L, 1L), X8.2 = c(1L,
1L, 1L, 1L, 1L, 1L), X9.1 = c(1L, 1L, 1L, 1L, 1L, 1L), X9.2 = c(1L,
1L, 1L, 1L, 1L, 1L), X9.3 = c(1L, 1L, 1L, 1L, 1L, 1L), X9.4 = c(1L,
1L, 1L, 1L, 1L, 1L), X10.1 = c(1L, 1L, 1L, 1L, 1L, 1L), X10.2 = c(1L,
1L, 1L, 1L, 1L, 1L), X10.3 = c(1L, 1L, 1L, 1L, 1L, 1L), X10.4 = c(1L,
1L, 1L, 1L, 1L, 1L), X10.5 = c(1L, 1L, 1L, 1L, 1L, 1L), X10.6 = c(1L,
1L, 1L, 1L, 1L, 1L), X10.7 = c(1L, 1L, 1L, 1L, 1L, 1L), X10.8 = c(1L,
1L, 1L, 1L, 1L, 1L), X10.9 = c(1L, 1L, 1L, 1L, 1L, 1L), X11.1 = c(1L,
1L, 1L, 1L, 1L, 1L), X11.2 = c(1L, 1L, 1L, 1L, 1L, 1L), X11.3 = c(1L,
1L, 1L, 1L, 1L, 1L), X11.4 = c(1L, 1L, 1L, 1L, 1L, 1L), X11.5 = c(1L,
1L, 1L, 1L, 1L, 1L), X11.6 = c(1L, 1L, 1L, 1L, 1L, 1L), X11.7 = c(1L,
1L, 1L, 1L, 1L, 1L), X11.8 = c(1L, 1L, 1L, 1L, 1L, 1L), X11.9 = c(1L,
1L, 1L, 1L, 1L, 1L), X11.1.1 = c(1L, 1L, 1L, 1L, 1L, 1L), X11.11 = c(1L,
1L, 1L, 1L, 1L, 1L), X11.12 = c(1L, 1L, 1L, 1L, 1L, 1L), X11.13 = c(1L,
1L, 1L, 1L, 1L, 1L), X11.14 = c(1L, 1L, 1L, 1L, 0L, 0L), X11.15 = c(1L,
1L, 1L, 1L, 1L, 0L), X11.16 = c(1L, 1L, 1L, 1L, 1L, 1L), X12.1 = c(1L,
1L, 1L, 1L, 1L, 1L), X12.2 = c(1L, 1L, 1L, 1L, 1L, 1L), X12.3 = c(1L,
1L, 1L, 0L, 1L, 1L), X12.4 = c(1L, 1L, 1L, 1L, 1L, 1L), X12.5 = c(1L,
1L, 1L, 1L, 1L, 1L), X12.6 = c(1L, 1L, 1L, 1L, 1L, 1L), X12.7 = c("SI",
"SI", "SI", "SI", "NO", "NO"), X12.8 = c(0L, 0L, 0L, 0L, NA,
NA), X14.1 = c(1L, 1L, 1L, 1L, 1L, 1L), X14.2 = c(1L, 1L, 1L,
1L, 0L, 1L), Puntos.máximos = c(71L, 71L, 71L, 71L, 70L, 70L),
Puntos.alcanzados = c(70L, 70L, 69L, 69L, 68L, 67L), X. = c(98.59,
98.59, 97.18, 97.18, 97.14, 95.71), No..de.Padres = c(7L,
7L, 6L, 7L, 7L, 7L), Horas = c(14L, 14L, 12L, 14L, 14L, 14L
)), row.names = c(NA, 6L), class = "data.frame")
You can try to exclude the character columns from pivoting. Not entirely sure if the result will be what you expected though.
library(ggplot2)
library(tidyr)
dff <- pivot_longer(df, colnames(df)[!sapply( df, is.character )] )
ggplot(dff, aes(x = name, y = Localidad , fill = value)) +
geom_tile(colour="gray80", size=0.2) +
geom_text(aes(label=value)) +
theme_minimal() +
scale_fill_distiller(palette = "YlGnBu", direction = -1, na.value = "white")
# plot

Add text outside plot area in ggplot2

I am trying to create the following plot and I want to add some additional illustration to the plot to point the reader to some important characteristics of it.
I am trying to add the 4 text descriptions (hopefully with the line blocks) to the graph.
Is this possible with ggplot or should I look to some other package to do this?
The length of the lines are related to the dispersion of the points, I do not mind manually adding these lines with a fixed width for each but it would be also cool to see if there is a way to make the line lengths dependent on the dispersion (but again really not important!).
I am plotting predicted probabilities from one model vs another model.
I have a data frame called x
ggplot code:
ggplot(x, aes(x=mod1, y=mod2, colour = actual)) +
geom_point(alpha = 1) +
geom_density_2d() +
stat_density_2d(aes(fill = ..level..), geom="polygon", alpha = 1) +
labs(x = "plot1 results", subtitle = "--------------- subtitle which can be quite long like this -------------------", y = "plot2 results", title = "title") +
theme_bw(base_size = 11, base_family = "") +
theme(aspect.ratio = 1) +
scale_color_manual(values=c("yellow", "grey"))
Data:
structure(list(mod1 = c(0.0428680343284435, 0.846016555762155,
0.326787531886571, 0.553755029639909, 0.687879627696911, 0.0960930400203601,
0.744828994271728, 0.540002328947346, 0.220881375043177, 0.0702872626691926,
0.326427351123072, 0.242150667845905, 0.0585994813808256, 0.0476546237354429,
0.677024473452915, 0.141965306592508, 0.580238736830929, 0.209089243871524,
0.202588588164632, 0.462602376730863, 0.170047796107216, 0.0599183763024999,
0.144128948353236, 0.704983877871062, 0.148981617804389, 0.0259100317297817,
0.070919748619838, 0.847120835339521, 0.280625159241402, 0.241346727659237,
0.285528700584795, 0.522832128634093, 0.0495932506050149, 0.191222810970403,
0.848539280298263, 0.460823513872965, 0.297519579850422, 0.299706327222228,
0.29118588708967, 0.569263883004122, 0.814633900535549, 0.268597010973285,
0.583651002250045, 0.0771418703083737, 0.272577428138581, 0.0652980769011686,
0.0645563141023351, 0.185751367095499, 0.163771389063719, 0.922377554059713,
0.118440921292355, 0.601015657502687, 0.458036991708823, 0.706976353965206,
0.557104373519309, 0.336600458082119, 0.365573066188997, 0.349695386601579,
0.885005310870269, 0.340463030723538, 0.646538075407289, 0.347697108751173,
0.23887463827597, 0.222397529338268, 0.261741960415693, 0.255160177543014,
0.394003003413919, 0.350059479442216, 0.443055385407801, 0.999532291288415,
0.025735898423369, 0.369031728988488, 0.105252031223466, 0.233622390662318,
0.258892195873903, 0.101629573908821, 0.260570520936073, 0.209063089308277,
0.265239879267213, 0.137555975136797, 0.0855678812173928, 0.73880289082864,
0.802094313494666, 0.973899882546715, 1, 0.943515501797875, 0.020488912431986,
0.138004937708603, 0.111975864093794, 0.818441921329778, 0.0392858886896277,
0.593233184537478, 0.186525732878499, 0.467999992773845, 0.653350287632996,
0.550997098851144, 0.525885581162108, 0.98809473982989, 0.304496141867713,
0.233695105089987, 0.168798462655651, 0.276530329800917, 0.0258753799208103,
0.398677230034304, 0.601193870473126, 0.33018455671484, 0.546663783633736,
0.0732052848477258, 0.299579613100531, 0.195704039249802, 0.41032712235619,
0.358664485435842, 0.102182019177211, 0.111387254699232, 0.558663221258304,
0.701343535849789, 0.565610725546385, 0.165796298650061, 0.844108924341358,
0.65239500174214, 0.795485589918214, 0.575301458796068, 0.179957090666757,
0.883763860288409, 0.491162742628921, 0.615729900118775, 0.561630408279962,
0.284792242641951, 0.969432341514501, 0.477295676601633, 0.375561806375457,
0.206089561651849, 0.465548611290696, 0.336325053961017, 0.373667379797929,
0.570137795506596, 0.491918452884049, 0.190682849018188, 0.225091942414155,
0.410820863660711, 0.227786666632663, 0.138933996506405, 0.0334324000181915,
0.162488265240681, 0.805662813620657, 0.0933958810234599, 0.153939073268865,
0.857625661330725, 0.0963304147676984, 0.380415923377483, 0.0519017480874503,
0.0779283157397147, 0.107444894718232, 0.10441308985682, 0.712516878369368,
0.284157191775836, 0.265396916220893, 0.0400873874170811, 0.0393202404365727,
0.477044935156301, 0.124630185722413, 0.0650517287131615, 0.124980600269956,
0.320411167606173, 0.248807440955571, 0.082630461317074, 0.756327325304615,
0.225984532731912, 0.403768216845618, 0.630147108079651, 0.15594857762537,
0.0839887294293966, 0.150716106034452, 0.121445695528259, 0.35994354107865,
0.368300361452314, 0.24483459459127, 0.152527988563374, 0.551278085315308,
0.150034610924398, 0.250987845804079, 0.0565821061235104, 0.712734202323831,
0.335055664246889, 0.756065329175747, 0.29393094296416, 0.106641584154548,
0.420158769864025, 0.356454970300771, 0.47515374360064, 0.580812111995106,
0.000717130307059303, 0.154790410888561, 0.219513327079438, 0.364778107570437,
0.412859716955486, 0.692560953694384, 0.32077704674508, 0.0877703437440174,
0.275616887306484, 0.163821283189476, 0.808953944759211, 0.160209449757217,
0.394250485937628, 0.790498740283875, 0.447255960695868, 0.755359668103058,
0.537682737841053, 0.593538678937104, 0.196985122041494, 0.276494311008183,
0.0872459557748893, 0.235580847722567, 0.694748763162609, 0.354039737000946,
0.44200303784393, 0.165473335918548, 0.467358717157778, 0.0892700946170289,
0.99962830878852, 0.14014494671621, 0.0690684955560723, 0.145798038742771,
0.250339990117619, 0.341301599717557, 0.999244229176301, 0.478057677073386,
0.499445867397323, 0.676004506849537, 0.719051923777321, 0.105192369641408,
0.299010580450917, 0.684795758632428, 0.291732308319941, 0.0270760029206405,
0.231610195736126, 0.611894118472659, 0.252430564645428, 0.131649581553132,
0.510978021474668, 0.462763808757614, 0.237101727522011, 0.119024947839695,
0.135741592765658, 0.494417857244557, 0.173666298996107, 0.318988535201983,
0.173381070170447, 0.142219387103895, 0.656232876487217, 0.205846250120757,
0.122824951848628, 0.162495489321409, 0.872492951796276, 0.909080602176691,
0.66011964524832, 0.124102526142048, 0.138596610491767, 0.402363981778695,
0.443105000056591, 0.351367846003605, 0.32105628268368, 0.218800962448852,
0.118826349897186, 0.276304590212166, 0.0610016455322748, 0.558898605504491,
0.896861618042103, 0.219229588571431, 0.452525152002443, 0.200601477807967,
0.497083783289865, 0.110887650356807, 0.423945207587228, 0.0788144014885928,
0.389111968949349, 0.234569095311629, 0.574908316733503, 0.0650452798024705,
0.420115866748883, 0.457514278320592, 0.880126441902655, 0.0521590907403362,
0.961235825781951, 0.270440842694789, 0.114619887870278, 0.34148441206563,
0.334334164627438, 0.272603252040328, 0.0726735743345817, 0.0492160623167159,
0.718306549552725, 0.186814116478276, 0.358501035429906, 0.657342239918421,
0.336900266574, 0.704012501445306, 0.171667389605084, 0.0887593837030433,
0.194855062569366, 0.992724683416655, 0.217781466318124, 0.244417900635284,
0.772342328020165, 0.0787202755309474, 0.360467546646677, 0.208455253587378,
0.412048159709031, 0.237356742436605, 0.0975803958838624, 0.211064024176639,
0.311204223705994, 0.0583237843898937, 0.389651029808109, 0.345025935039879,
0.624846648212751, 0.58851623834231, 0.887105187034623, 0.321097430780683,
0.235333454689797, 0.317948692315331, 0.221829921658406, 0.741550229770297,
0.20323638533706, 0.300011118692256, 0.10709664298948, 0.128658851710521,
0.215608428571485, 0.850613750148793, 0.520018226875275, 0.229616805359878,
0.795191910398009, 0.0903188238048897, 0.397921159282847, 0.203044598795871,
0.56273414261286, 0.574577913744773, 0.442200678899054, 0.245465935323322,
0.278019517090414, 0.352947382006002, 0.174645818312427, 0.122145774176944,
0.170757436677423, 0.397071879644391, 0.191901705813107, 0.0904542790515756,
0.185273222274775, 0.132590145000319, 0.371241327758872, 0.58624534957165,
0.0326746116517388, 0.314917326956508, 0.949721350006339, 0.452309070827074,
0.103763927657044, 0.0701849859768701, 0.586205681965722, 0.1872300676421,
0.362091824661685, 0.528553649819102, 0.190539638058716, 0.0327545040641537,
0.762165679327963, 0.274571490276717, 0.512464730498834, 0.27234499730487,
0.650035734997207, 0.713152866696705, 0.199327736885447, 0.888922212975112,
0.256517093465039, 0.0491122775280585, 0.145917596045208, 0.519396637888038,
0.0794241734859925, 0.109718966941177, 0.149020433838973, 0.508447476265555,
0.175000348118242, 0.226815958091545, 0.282973740661336, 0.320684074902339,
0.299983143281491, 0.081224779932806, 0.959972054857087, 0.40619879677503,
0.844555422937453, 0.534525371689877, 0.220441245612505, 0.188279840325184,
0.184744989425758, 0.577591333604708, 0.182105298203728, 0.578046328506155,
0.447224424542321, 0.545195283609091, 0.620149367286776, 0.143021628347417,
0.365110938943906), actual = structure(c(1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L,
2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 2L, 1L, 1L,
1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 2L, 1L, 1L, 2L, 1L, 1L, 2L, 1L, 2L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 2L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L,
1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L,
2L, 1L, 2L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L,
1L, 1L, 1L, 1L, 1L, 2L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 1L, 2L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 2L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L), .Label = c("0",
"1"), class = "factor"), mod2 = c(0.00921301729977131, 0.420679152011871,
0.280125766992569, 0.829287350177765, 0.0740553513169289, 0.0137514220550656,
0.345879256725311, 0.675718426704407, 0.224963515996933, 0.0168505609035492,
0.206158310174942, 0.0561505369842052, 0.013946115039289, 0.0312005542218685,
0.812829315662384, 0.0040231547318399, 0.164083942770958, 0.144838228821754,
0.0544591136276722, 0.0705596581101418, 0.0993659123778343, 0.0502875261008739,
0.0711468532681465, 0.97149133682251, 0.0123780304566026, 0.0158327762037516,
0.0151439299806952, 0.161300778388977, 0.0351154617965221, 0.371416091918945,
0.102943770587444, 0.757962644100189, 0.0110324919223785, 0.047280989587307,
0.353544414043427, 0.103088781237602, 0.050556942820549, 0.0350653082132339,
0.401749402284622, 0.242998450994492, 0.95191890001297, 0.247199147939682,
0.877671599388123, 0.0228813849389553, 0.316035985946655, 0.0982891768217087,
0.105327241122723, 0.0394041128456593, 0.158778890967369, 0.965853333473206,
0.00885774753987789, 0.0148940868675709, 0.0758267268538475,
0.157344698905945, 0.551176071166992, 0.12992300093174, 0.0138051174581051,
0.475996285676956, 0.948372185230255, 0.134769633412361, 0.556590795516968,
0.241968929767609, 0.0591361075639725, 0.136440336704254, 0.0668027997016907,
0.0214910972863436, 0.168018579483032, 0.0699143782258034, 0.0613136924803257,
0.983657658100128, 0.01039685215801, 0.0587030127644539, 0.00913762766867876,
0.0317753851413727, 0.0524604544043541, 0.0171482041478157, 0.0351034365594387,
0.0221143364906311, 0.390063345432281, 0.0124582275748253, 0.0435651019215584,
0.960456311702728, 0.981251120567322, 0.962678015232086, 0.68353945016861,
0.971885144710541, 0.00406940141692758, 0.0203599724918604, 0.0633115172386169,
0.130489587783813, 0.00637582363560796, 0.755789935588837, 0.00400055898353457,
0.0196541585028172, 0.452250599861145, 0.902487516403198, 0.0917441099882126,
0.70908921957016, 0.854791462421417, 0.0794311910867691, 0.0273289680480957,
0.0311463791877031, 0.0127724697813392, 0.0723041146993637, 0.95717054605484,
0.264508247375488, 0.127880096435547, 0.0171502381563187, 0.0879878774285316,
0.057909045368433, 0.195128262042999, 0.0270854383707047, 0.0782773569226265,
0.0383500903844833, 0.372881323099136, 0.285864651203156, 0.116122633218765,
0.0114724459126592, 0.158793538808823, 0.761920690536499, 0.861652076244354,
0.227078512310982, 0.0417833961546421, 0.968308210372925, 0.249760672450066,
0.817656457424164, 0.657787919044495, 0.0230655912309885, 0.991730153560638,
0.243526577949524, 0.156855791807175, 0.269827306270599, 0.2051682472229,
0.254308879375458, 0.0800860077142715, 0.34795343875885, 0.972077071666718,
0.0477356761693954, 0.0464455783367157, 0.736665904521942, 0.0210415944457054,
0.0383482202887535, 0.00386064685881138, 0.012203705497086, 0.857867896556854,
0.0814997106790543, 0.0443238392472267, 0.988256871700287, 0.0165475029498339,
0.0615949258208275, 0.0449854917824268, 0.0454509183764458, 0.01393414568156,
0.0262223742902279, 0.186277061700821, 0.0324785746634007, 0.033482164144516,
0.00819115899503231, 0.0117478491738439, 0.0783571749925613,
0.0223740469664335, 0.0198381245136261, 0.0501869209110737, 0.0376051589846611,
0.0624551437795162, 0.0314894691109657, 0.860675990581512, 0.0612487271428108,
0.276889532804489, 0.0167709998786449, 0.0528305657207966, 0.00499858101829886,
0.0550522655248642, 0.0401820614933968, 0.15572227537632, 0.025402145460248,
0.0761110484600067, 0.0188306048512459, 0.0380858443677425, 0.0132785346359015,
0.0640550553798676, 0.00517340190708637, 0.0772885754704475,
0.19677597284317, 0.70759129524231, 0.147291049361229, 0.0479679442942142,
0.448112070560455, 0.438730537891388, 0.1216806396842, 0.00735889840871096,
0.400070250034332, 0.11030688136816, 0.0442567691206932, 0.843577682971954,
0.558653950691223, 0.0176850743591785, 0.0946979001164436, 0.0153300678357482,
0.0788581073284149, 0.287300169467926, 0.18515208363533, 0.0233458057045937,
0.222889557480812, 0.0536097027361393, 0.046075414866209, 0.454137802124023,
0.0345671623945236, 0.0211565420031548, 0.00878079421818256,
0.0967049226164818, 0.0367577895522118, 0.0918731242418289, 0.801138401031494,
0.863967061042786, 0.481592088937759, 0.0336476154625416, 0.042931966483593,
0.146649375557899, 0.879879474639893, 0.0114125544205308, 0.00469835428521037,
0.0382965281605721, 0.00703405775129795, 0.0215587317943573,
0.653248488903046, 0.0782845988869667, 0.121728673577309, 0.0159873776137829,
0.146458551287651, 0.0206322781741619, 0.0499792955815792, 0.406131267547607,
0.0681000128388405, 0.0272951126098633, 0.0921002179384232, 0.705728650093079,
0.0432888120412827, 0.0904701724648476, 0.701448082923889, 0.150377616286278,
0.0676496997475624, 0.0228539109230042, 0.0765143036842346, 0.113855704665184,
0.0267140381038189, 0.0929989665746689, 0.152857646346092, 0.0418933369219303,
0.565863370895386, 0.0166599620133638, 0.0156008023768663, 0.0115091372281313,
0.903479337692261, 0.986901104450226, 0.928888380527496, 0.0101279402151704,
0.0802175477147102, 0.0816037356853485, 0.184011369943619, 0.306637078523636,
0.153407230973244, 0.0167400408536196, 0.22508542239666, 0.0621875934302807,
0.045804962515831, 0.171572059392929, 0.282828807830811, 0.0179158430546522,
0.840476810932159, 0.0105379819869995, 0.0114276595413685, 0.0119720129296184,
0.181616917252541, 0.0978458821773529, 0.12760978937149, 0.302467346191406,
0.833696305751801, 0.0464334487915039, 0.945941805839539, 0.511578798294067,
0.974729835987091, 0.0164413973689079, 0.0989365875720978, 0.0765514746308327,
0.0109183257445693, 0.27131775021553, 0.107158131897449, 0.0736118629574776,
0.00482818158343434, 0.0201019216328859, 0.941181838512421, 0.0378244519233704,
0.797275304794312, 0.351534575223923, 0.117122322320938, 0.493010193109512,
0.0246974248439074, 0.0206503849476576, 0.0464012213051319, 0.959466278553009,
0.103862524032593, 0.0122975073754787, 0.380784571170807, 0.0136013478040695,
0.184185728430748, 0.0669872164726257, 0.214213669300079, 0.0391909405589104,
0.0619069524109364, 0.0159242562949657, 0.0373520478606224, 0.00958761665970087,
0.377378851175308, 0.166095584630966, 0.925777494907379, 0.0208236053586006,
0.0404847823083401, 0.559196531772614, 0.0746391415596008, 0.325236350297928,
0.0599571503698826, 0.26615184545517, 0.0652189999818802, 0.0173883624374866,
0.0242639016360044, 0.024857934564352, 0.0169697199016809, 0.911997854709625,
0.100104205310345, 0.167153507471085, 0.787109971046448, 0.0342921391129494,
0.15250888466835, 0.0209930054843426, 0.0491697303950787, 0.13340713083744,
0.471260368824005, 0.0106122875586152, 0.144313588738441, 0.0787744149565697,
0.235925808548927, 0.0196361448615789, 0.0727006196975708, 0.0628127604722977,
0.0305791813880205, 0.0411793142557144, 0.195792764425278, 0.0215679779648781,
0.239042669534683, 0.150531396269798, 0.0177980363368988, 0.0576319955289364,
0.959489762783051, 0.480692893266678, 0.0187541544437408, 0.00829488877207041,
0.0474584363400936, 0.0482899323105812, 0.785768091678619, 0.0142318215221167,
0.0503279566764832, 0.00939451158046722, 0.37018147110939, 0.0408202894032001,
0.196333780884743, 0.128449380397797, 0.934917628765106, 0.792946517467499,
0.138556912541389, 0.706277251243591, 0.00852821208536625, 0.0416146814823151,
0.0253815017640591, 0.825974524021149, 0.0193344969302416, 0.0097988685593009,
0.0383418351411819, 0.791619479656219, 0.138332143425941, 0.017676180228591,
0.0617045052349567, 0.00605513388291001, 0.0927852019667625,
0.0261132270097733, 0.953198134899139, 0.182122096419334, 0.958361387252808,
0.270839661359787, 0.0256280936300755, 0.0315133333206177, 0.0611352697014809,
0.410940438508987, 0.0302151944488287, 0.868182957172394, 0.0327513180673122,
0.0963760241866112, 0.955038785934448, 0.0473414175212383, 0.0430381260812283
)), row.names = c(NA, 400L), class = "data.frame")

setting color axis limits in ggplot2

I am trying to make a heat-map of chlorophyll fluorescence vs depth and time. I have things working pretty ok, but I'm trying to improve my colour contrast. I generate my heatmap with the following code.
ggplot(subset(ctdamotInt2, variable == 'fluorescence'), aes(time, depth)) +
geom_tile(aes(fill = log10(value))) + scale_y_reverse(limits = c(110, 0)) +
scale_x_time(limits = c(min(subset(ctdamot, variable == 'nh4')$time) - 2 * 60^2, max(subset(ctdamot, variable == 'nh4')$time) + 2* 60^2)) +
geom_point(data = samplesCTD, aes( x = time, y = depth)) +
scale_fill_gradient2(low = "blue", mid = "white", high = "green")
Generally I am finding that the dark green colours essentially never get utilized and so my heatmap ends up looking washed out and doesn't do a great job of communicating where chlorophyll fluorescence is greatist If I were working in matlab, I would get around this by setting
caxis([-1 0.4])
which would set all values above 0.4 to the maximum green value. You wouldn't be able to tell the relative difference of the really high values, but you'd at least be able to get a better idea about the relative differences of the intermediate values that make up most of the plot. Any suggestions on how I can have a larger proportion of this plot be green? I suppose I could manually rescale the input values, but would rather not if there is a better way.
Edit: At the request of Mike H
dput(head(ctdamotInt2,100))
structure(list(variable = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("temperature", "salinity",
"fluorescence", "oxygen", "nh4"), class = "factor"),
depth = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), time = structure(c(1482764087,
1482767687, 1482771287, 1482774887, 1482778487, 1482782087,
1482785687, 1482789287, 1482792887, 1482796487, 1482800087,
1482803687, 1482807287, 1482810887, 1482814487, 1482818087,
1482821687, 1482825287, 1482828887, 1482832487, 1482836087,
1482839687, 1482843287, 1482846887, 1482850487, 1482854087,
1482857687, 1482861287, 1482864887, 1482868487, 1482872087,
1482875687, 1482879287, 1482882887, 1482886487, 1482890087,
1482893687, 1482897287, 1482900887, 1482904487, 1482908087,
1482911687, 1482915287, 1482918887, 1482922487, 1482926087,
1482929687, 1482933287, 1482936887, 1482940487, 1482944087,
1482947687, 1482951287, 1482954887, 1482958487, 1482962087,
1482965687, 1482969287, 1482972887, 1482976487, 1482980087,
1482983687, 1482987287, 1482990887, 1482994487, 1482998087,
1483001687, 1483005287, 1483008887, 1483012487, 1483016087,
1483019687, 1483023287, 1483026887, 1483030487, 1483034087,
1483037687, 1483041287, 1483044887, 1483048487, 1483052087,
1483055687, 1483059287, 1483062887, 1483066487, 1483070087,
1483073687, 1483077287, 1483080887, 1483084487, 1483088087,
1483091687, 1483095287, 1483098887, 1483102487, 1483106087,
1483109687, 1483113287, 1483116887, 1483120487), class = c("POSIXct",
"POSIXt")), value = c(27.3483, 27.3483, 27.3483, 27.3483,
27.4404348314607, 27.5325696629213, 27.624704494382, 27.7168393258427,
27.8089741573034, 27.901108988764, 27.9932438202247, 28.0853786516854,
28.1006709677419, 28.1151870967742, 28.1297032258065, 28.1602961677656,
28.3392342471866, 28.5181723266075, 28.6971104060285, 28.8760484854494,
29.0549865648704, 29.1744078768732, 29.2330425521923, 29.2916772275114,
29.3503119028306, 29.4089465781497, 29.4675812534688, 29.5262159287879,
29.5233725024786, 29.5198033650201, 29.5162342275617, 29.5126650901032,
29.5090959526448, 29.5055268151863, 29.5019576777279, 29.4983885402694,
29.494819402811, 29.4392079391567, 29.3230472306014, 29.2068865220461,
29.0907258134908, 28.9745651049355, 28.8584043963802, 28.7422436878249,
28.6260829792696, 28.5099222707143, 28.5396702257581, 28.6045126836247,
28.6693551414913, 28.734197599358, 28.7990400572246, 28.8638825150912,
28.9287249729579, 28.9935674308245, 29.0584098886912, 29.1232523465578,
29.1880948044244, 29.2529372622911, 29.3177797201577, 29.3826221780244,
29.447464635891, 29.5123070937576, 29.4047436790674, 29.2746548739928,
29.1445660689182, 29.0144772638436, 28.8843884587691, 28.7542996536945,
28.6242108486199, 28.4941220435453, 28.4440444629526, 28.4161338799902,
28.3882232970279, 28.3603127140655, 28.3324021311032, 28.3044915481409,
28.2765809651785, 28.2486703822162, 28.2207597992539, 28.1928492162915,
28.1649386333292, 28.1370280503668, 28.1091174674045, 28.0812068844422,
28.0532963014798, 28.0253857185175, 27.9974751355552, 27.9695645525928,
27.9416539696305, 27.9137433866682, 27.8858328037058, 27.8579222207435,
27.8300116377811, 27.8021010548188, 27.7741904718565, 27.7462798888941,
27.7183693059318, 27.6904587229695, 27.6625481400071, 27.6346375570448
)), .Names = c("variable", "depth", "time", "value"), row.names = c(NA, 100L), class = "data.frame")

some data are not showing up on the ggplot2 window

head(x)
Region Type Date count
1 Americas Point 2011-10-26 1
2 Americas Point 2011-10-27 2
3 Americas Point 2011-10-31 1
4 Americas Point 2011-11-01 1
5 Americas Point 2011-12-05 1
6 Americas Point 2011-12-07 1
dput(x)
structure(list(Region = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L), .Label = "Americas", class = "factor"), Type = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "Point", class = "factor"),
Date = structure(c(15273, 15274, 15278, 15279, 15313, 15315,
15316, 15320, 15341, 15342, 15351, 15358, 15370, 15390, 15392,
15405, 15407, 15411, 15418, 15421, 15433, 15467, 15470, 15482,
15495, 15497, 15503, 15517, 15530, 15551, 15554, 15582, 15586,
15589, 15593, 15601, 15602, 15610, 15615, 15616, 15624, 15643,
15645, 15656, 15663, 15664, 15665, 15672, 15673, 15677, 15678,
15679, 15680, 15684, 15686, 15693, 15694, 15698, 15699, 15705,
15706, 15707, 15712, 15713, 15714, 15719, 15720, 15721, 15727,
15736, 15740, 15741, 15742, 15743), class = "Date"), count = c(1L,
2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L)), .Names = c("Region",
"Type", "Date", "count"), row.names = c(NA, -74L), class = "data.frame")
I am trying to build a stack bar graph as follows:
ggplot(x, aes(Date, count, group=Region)) +
geom_bar(aes(fill=Type, width=0.3),stat="identity", position="stack") +
scale_x_date(breaks = "1 month",
minor_breaks = "2 weeks",
labels=date_format("%b-%y")) +
geom_smooth(method="lm", se=T, size=0.5, colour="yellow") +
facet_wrap(~Region)
by default, I see some missing points but when I stretched the plot window, points appear. I really need all the points in the chart, other wise it looks like I am miss reporting the data. Any suggestions how can I address this so that I see all the data points on the chart. My window size is 500 by 500.
Indeed, by increasing the screen size more bars appear. You can't see them in the small window of the R console because the width of the bars is too small. But when you save it, the bars can be seen in the output:
plot <- ggplot(x, aes(Date, count, group=Region)) +
geom_bar(aes(fill=Type, width=0.3),stat="identity", position="stack") +
scale_x_date(breaks = "1 month",
minor_breaks = "2 weeks") +
geom_smooth(method="lm", se=T, size=0.5, colour="yellow") +
facet_wrap(~Region)
ggsave("test.pdf",plot )
To see all the points in the R console increase the width, for instance:
(plot <- ggplot(x, aes(Date, count, group=Region)) +
geom_bar(aes(fill=Type, width=1),stat="identity", position="stack") +
scale_x_date(breaks = "1 month",
minor_breaks = "2 weeks") +
geom_smooth(method="lm", se=T, size=0.5, colour="yellow") +
facet_wrap(~Region))

plotting only time using ggplot2

I have a data frame like this:
head(yy)
Team Date STime ETime
1 A 2012-03-06 07:03 10:13
2 A 2012-03-06 07:03 10:13
3 A 2012-03-06 07:03 10:13
4 A 2012-03-06 07:03 10:13
5 A 2012-03-06 07:03 10:13
6 A 2012-03-06 07:03 10:13
dput(yy)
dput(yy)
structure(list(Team = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "A", class = "factor"),
Date = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "2012-03-06", class = "factor"),
STime = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "07:03", class = "factor"),
ETime = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "10:13", class = "factor")), .Names = c("Team",
"Date", "STime", "ETime"), class = "data.frame", row.names = c(NA,
-50L))
I like to see the y-axis from 00:00 23:59 in 2 hours increment and be able to draw a red line on STime value.
I have somthing like this but it does not look right:
ggplot(yy, aes(Date, ETime, group="Team")) + geom_jitter(size=0.05) + facet_wrap( ~ Team) + geom_hline(yintercept=yy$Stime, colour="red", size=2)
how would you do this in ggplot2? Can somebody give me pointers/start me in the right direction?
Regards,
You have to format your times into actual times. Right now they are factors (Check your data frame with str(yy)). When ETime is plotted, the single time is plotted as 1 and labeled "10:13." So, the solution below first converts the string "10:13" into a time (strptime) then converts it to POSIXct, or seconds since an origin (1/1/1970).
library(ggplot2); library(scales)
#Convert date string into POSIXct format
yy$STime <- as.POSIXct(strptime(yy$STime, format = "%H:%M", tz = "UTC"))
yy$ETime <- as.POSIXct(strptime(yy$ETime, format = "%H:%M", tz = "UTC"))
#Define y-axis limits
lims <- as.POSIXct(strptime(c("0:00","23:59"), format = "%H:%M", tz= "UTC"))
ggplot(yy, aes(Date, ETime, group="Team")) + geom_jitter(size=1) + facet_wrap( ~ Team) +
geom_hline(data = yy, aes(yintercept= as.numeric(STime)), colour="red", size=2) +
scale_y_datetime(limits =lims, breaks=date_breaks("2 hour"),
labels=date_format("%H:%M", tz = "UTC") )
Note on geom_line to date axis.
Pay attention to your timezones too. Otherwise R/ggplot will format things according to your local time zone.

Resources