使用r中的facet_wrap可以实现两个变量叠加一个变量单独表示吗?

问题描述 投票:0回答:0

首先,这是我的数据框输出代码。

structure(list(Date = 2010:2040, Principal = c(684.87465504954, 
975.003026846142, 1050.6950457127, 1132.26323271654, 1220.16377006145, 
1314.8882545613, 1416.96644696816, 1526.9692347381, 1645.51182480402, 
1773.25718421189, 1910.91974786238, 2059.26941409425, 2219.13585045513, 
2391.41313374055, 2577.06475025127, 2777.12898423355, 2992.72472463801, 
3225.05772267236, 3475.42733514413, 3745.23379130666, 4035.98602384922, 
4349.31010782725, 4686.95835472869, 5050.81911253626, 5442.92732659417, 
5865.47592034218, 6320.82805956582, 6811.53036875204, 7340.32717346504, 
7910.17584839468, 2071.69357387502), Interest = c(5608.05592192545, 
7415.57107578718, 7339.87905692061, 7258.31086991678, 7170.41033257186, 
7075.68584807202, 6973.60765566516, 6863.60486789522, 6745.0622778293, 
6617.31691842143, 6479.65435477093, 6331.30468853906, 6171.43825217819, 
5999.16096889277, 5813.50935238204, 5613.44511839977, 5397.84937799531, 
5165.51637996096, 4915.14676748919, 4645.34031132666, 4354.5880787841, 
4041.26399480606, 3703.61574790463, 3339.75499009705, 2947.64677603915, 
2525.09818229114, 2069.7460430675, 1579.04373388128, 1050.24692916828, 
480.398254238642, 25.949951783305), Balance = c(99315.1253449505, 
98340.1223181043, 97289.4272723916, 96157.1640396751, 94937.0002696136, 
93622.1120150523, 92205.1455680842, 90678.1763333461, 89032.664508542, 
87259.4073243302, 85348.4875764678, 83289.2181623735, 81070.0823119184, 
78678.6691781778, 76101.6044279266, 73324.475443693, 70331.750719055, 
67106.6929963826, 63631.2656612385, 59886.0318699319, 55850.0458460826, 
51500.7357382554, 46813.7773835267, 41762.9582709904, 36320.0309443963, 
30454.5550240541, 24133.7269644883, 17322.1965957362, 9981.86942227119, 
2071.69357387652, 0)), class = "data.frame", row.names = c(NA, 
-31L))

在我的数据框中,有称为本金、利息和余额的列。我想通过使用 facet_wrap 为这些列绘制一个 geom_line 图,并打印出两个图。

两个图的 x 轴将使用日期列。对于带有 facet_wrap 函数的第一张图,我想同时叠加 Principals 和 Interests。在第二张图中,我只想表示平衡。是否有可能实现我试图表示的图形?

r ggplot2 rstudio overlay facet-wrap
© www.soinside.com 2019 - 2024. All rights reserved.