I am preparing a time series plot using the ggplot function. It includes
an area plot outlined at its edges with a line plot. For some reason the
line plot, drawn with geom_line(), has some broken portions where the
line does not appear, although the filled geom_area() part of the plot
is shown. The problem is related to the last line of code because when I
remove it, the problem disappears.
Why is this happening and what can I do about it? Thank you. Philip
library(tidyverse)
df <- dget("df.txt")
mnGr <- 345.666605809
mnGDP <- 859.752763485
ggplot(df)+
geom_area(aes(x=Date,y=GDP*(mnGr/mnGDP)-Gr),
fill="red",alpha=0.3)+
geom_line(aes(x=Date,y=GDP*(mnGr/mnGDP)-Gr),
colour="black",size=1)+
scale_y_continuous(position="right",limits=c(-30,30))
structure(list(Date = structure(c(-3287, -3197, -3106, -3014,
-2922, -2832, -2741, -2649, -2557, -2467, -2376, -2284, -2192,
-2101, -2010, -1918, -1826, -1736, -1645, -1553, -1461, -1371,
-1280, -1188, -1096, -1006, -915, -823, -731, -640, -549, -457,
-365, -275, -184, -92, 0, 90, 181, 273, 365, 455, 546, 638, 730,
821, 912, 1004, 1096, 1186, 1277, 1369, 1461, 1551, 1642, 1734,
1826, 1916, 2007, 2099, 2191, 2282, 2373, 2465, 2557, 2647, 2738,
2830, 2922, 3012, 3103, 3195, 3287, 3377, 3468, 3560, 3652, 3743,
3834, 3926, 4018, 4108, 4199, 4291, 4383, 4473, 4564, 4656, 4748,
4838, 4929, 5021, 5113, 5204, 5295, 5387, 5479, 5569, 5660, 5752,
5844, 5934, 6025, 6117, 6209, 6299, 6390, 6482, 6574, 6665, 6756,
6848, 6940, 7030, 7121, 7213, 7305, 7395, 7486, 7578, 7670, 7760,
7851, 7943, 8035, 8126, 8217, 8309, 8401, 8491, 8582, 8674, 8766,
8856, 8947, 9039, 9131, 9221, 9312, 9404, 9496, 9587, 9678, 9770,
9862, 9952, 10043, 10135, 10227, 10317, 10408, 10500, 10592,
10682, 10773, 10865, 10957, 11048, 11139, 11231, 11323, 11413,
11504, 11596, 11688, 11778, 11869, 11961, 12053, 12143, 12234,
12326, 12418, 12509, 12600, 12692, 12784, 12874, 12965, 13057,
13149, 13239, 13330, 13422, 13514, 13604, 13695, 13787, 13879,
13970, 14061, 14153, 14245, 14335, 14426, 14518, 14610, 14700,
14791, 14883, 14975, 15065, 15156, 15248, 15340, 15431, 15522,
15614, 15706, 15796, 15887, 15979, 16071, 16161, 16252, 16344,
16436, 16526, 16617, 16709, 16801, 16892, 16983, 17075, 17167,
17257, 17348, 17440, 17532, 17622, 17713, 17805, 17897, 17987,
18078, 18170, 18262, 18353, 18444, 18536, 18628), class = "Date"),
GDP = c(40.672, 41.568, 42.68, 43.476, 44.696, 45.2, 46.144,
47.224, 47.668, 48.644, 49.444, 51.452, 52.652, 53.516, 54.676,
55.424, 57.364, 58.764, 60.172, 62.332, 64.428, 66.592, 67.464,
68.756, 69.584, 71.84, 72.484, 73.74, 75.408, 77.76, 79.544,
81.564, 83.876, 85.564, 87.224, 89.408, 91.46, 92.284, 94.196,
95.004, 96.388, 100.42, 103.736, 106.528, 108.256, 112.364,
114.492, 119.384, 124.86, 130.152, 134.652, 142.656, 149.424,
156.088, 162.384, 165.328, 167.572, 173.748, 182.328, 188.532,
196.288, 206.268, 208.464, 213.008, 219.892, 224.772, 229.704,
235.948, 241.296, 248.648, 255.176, 263.056, 271.352, 284.116,
292.9, 301.924, 309.756, 317.208, 324.72, 339.304, 355.992,
367.992, 372.82, 376.628, 383.004, 386.516, 389.56, 393.644,
403.236, 415.804, 428.96, 437.264, 447.84, 459.552, 465.18,
475.372, 486.096, 495.352, 503.872, 514.788, 518.612, 523.844,
530.22, 533.844, 552.484, 567.42, 581.68, 595.76, 610.948,
621.168, 631.392, 644.068, 656.16, 669.792, 679.132, 681.232,
691.928, 695.624, 697.684, 696.768, 694.008, 701.572, 704.796,
706.716, 710.008, 714.744, 721.66, 727.332, 733.952, 745.36,
750.068, 758.768, 772.656, 783.66, 800.784, 810.788, 823.972,
828.856, 832.976, 840.68, 844.208, 852.904, 864.544, 877.68,
891.748, 899.412, 912.564, 923.98, 934.612, 935.212, 938.872,
953.496, 975.24, 994.172, 1021.308, 1040.988, 1070.188, 1099.448,
1121.768, 1132.88, 1149.924, 1152.86, 1138.804, 1136.584,
1158.64, 1185.892, 1204.144, 1226.1, 1250.088, 1237.72, 1258.296,
1272.884, 1296.216, 1328.148, 1351.48, 1367.08, 1380.324,
1399.608, 1436.992, 1469.436, 1476, 1490.716, 1504.936, 1514.764,
1547.276, 1576.612, 1582.248, 1604.508, 1637.296, 1677.448,
1694.512, 1618.908, 1557.232, 1548.488, 1567.924, 1611.692,
1644.032, 1653.24, 1665.372, 1701.548, 1737.952, 1759.852,
1785.748, 1812.7, 1815.12, 1818.984, 1830.636, 1844.064,
1876.844, 1886.592, 1912.428, 1933.124, 1963.452, 1988.404,
2013.792, 2013.944, 1984.3, 1984.92, 2000.864, 1991.68, 1998.42,
2002.152, 2035.42, 2066.148, 2107.924, 2130.024, 2141.764,
2182.852, 2205.12, 2232.188, 2255.156, 2232.208, 2270.664,
2308.236, 2320.44, 2343.508, 2270.42, 2001.596, 2233.052,
2314.552, 2414.348), Gr = c(10.839, 11.284, 11.9, 12.065,
12.216, 12.496, 12.729, 12.835, 13.001, 13.114, 13.593, 14.148,
14.405, 15.27, 15.591, 15.882, 16.285, 16.961, 17.437, 18.085,
19.021, 19.558, 20.254, 21.007, 22.046, 21.875, 22.588, 23.107,
24.54, 24.469, 25.734, 27.101, 27.968, 29.417, 29.842, 30.929,
31.294, 32.358, 32.514, 32.846, 33.836, 35.628, 36.576, 37.18,
38.165, 39.898, 40.815, 42.25, 45.369, 46.477, 46.811, 50.659,
55.071, 59.112, 61.324, 63.461, 63.149, 63.985, 66.592, 67.834,
71.832, 73.67, 76.781, 77.921, 81.361, 81.509, 84.075, 84.015,
85.041, 89.665, 91.577, 95.637, 98.737, 98.391, 105.721,
107.923, 114.089, 114.638, 118.625, 125.424, 134.908, 141.928,
146.676, 150.236, 151.408, 152.032, 154.44, 155.46, 158.708,
167.568, 160.216, 170.284, 175.108, 174.64, 181.968, 185.64,
190.14, 188.472, 194.86, 200.804, 205.136, 204.756, 209.004,
212.872, 214.164, 226.948, 232.496, 238.02, 247.44, 248.992,
253.436, 259.452, 263.28, 272.044, 274.152, 279.428, 285.06,
305.248, 296.14, 286.972, 288.072, 306.956, 306.344, 307.872,
316.468, 310.336, 305.98, 311.772, 321.54, 304.892, 319.84,
324.964, 325.132, 327.576, 339.788, 340.436, 346.056, 349.084,
354.024, 356.108, 363.248, 364.116, 369.668, 375.38, 382.092,
395.928, 395.592, 404.512, 401.756, 413.52, 407.588, 415.524,
425.188, 431.824, 443.016, 450.9, 465.516, 478.976, 483.116,
483.564, 483.976, 491.552, 467.544, 462.896, 465.704, 475.62,
480.792, 495.432, 502.668, 491.304, 507.268, 513.82, 522.216,
527.652, 539.036, 543.048, 556.864, 565.14, 571.112, 585.62,
595.54, 604.332, 605.4, 618.532, 611.936, 642.264, 645.976,
645.456, 649.72, 647.74, 657.684, 627.176, 618.692, 607.788,
621.036, 637.668, 632.12, 644.08, 632.296, 645.648, 663.952,
682.032, 680.456, 689.048, 697.564, 697.76, 699.9, 711.48,
711.86, 724.392, 742.176, 748.448, 763, 765.22, 772.4, 775.144,
778.012, 799.332, 793.964, 809.94, 812.064, 812.312, 814.536,
826.24, 843.448, 871.46, 863.968, 875.528, 895.572, 911.432,
928.268, 936.528, 943.872, 956.348, 961.572, 973.504, 941.88,
878.744, 935.804, 943.2, 998.716)), row.names = c(NA, -241L
), class = c("tbl_df", "tbl", "data.frame"))
______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.