How to save plots generated by loop

I have a large database to test normality, and I am making plots through a loop
The data.frame

structure(list(paciente = c(6278, 6447, 6462, 6213, 6358, 6295, 
6523, 6174, 6343, 6270, 6483, 6307, 6467, 6219, 6446, 6274, 6001, 
6002, 6003, 6004, 6005, 6006, 6014, 6016, 6019, 6024, 6026, 6028, 
6030, 6031, 6043, 6044, 6048, 6051, 6053, 6054, 6059, 6066, 6074, 
6080, 6085, 6088, 6092, 6094, 6096, 6098, 6100, 6102, 6103, 6104, 
6105, 6109, 6110, 6118, 6124, 6126, 6127, 6129, 6132, 6133, 6136, 
6137, 6139, 6140, 6142, 6143, 6144, 6148, 6190, 6287, 6285, 6194, 
6167, 6206, 6271, 6555, 6416, 6513, 6374, 6400, 6325, 6371, 6440, 
6185, 6451, 6487, 6419, 6529, 6311, 6551, 6378, 6181, 6210, 6557, 
6203, 6175, 6150, 6470, 6204, 6166, 6355, 6477, 6534, 6286, 6561, 
6336, 6232, 6354, 6531, 6297, 6296, 6156, 6516, 6324, 6290, 6256, 
6176, 6410, 6277, 6254, 6173, 6151, 6499, 6248, 6546, 6280, 6152, 
6461, 6283, 6362, 6255, 6428, 6272, 6266, 6550, 6344, 6247, 6372, 
6454, 6237, 6539, 6387, 6215, 6251, 6330, 6180, 6515, 6238, 6201, 
6549, 6409, 6313, 6212, 6221, 6480, 6522, 6223, 6249, 6331, 6305, 
6352, 6484, 6357, 6281, 6257, 6432, 6545, 6345, 6379, 6236, 6498, 
6479, 6363, 6346, 6284, 6300, 6288, 6507, 6200, 6413, 6423, 6350, 
6326, 6229, 6368, 6386, 6434, 6509, 6244, 6293, 6530, 6427, 6453, 
6508, 6337, 6250, 6327, 6466, 6339, 6341, 6373, 6430, 6494, 6165, 
6188, 6207, 6463, 6431, 6268, 6230, 6351, 6485, 6383, 6364, 6239, 
6160, 6235, 6162, 6528, 6007, 6009, 6011, 6012, 6015, 6017, 6020, 
6022, 6023, 6029, 6032, 6036, 6038, 6039, 6040, 6041, 6045, 6049, 
6050, 6052, 6056, 6060, 6061, 6062, 6063, 6064, 6065, 6069, 6072, 
6081, 6082, 6083, 6086, 6087, 6089, 6090, 6091, 6093, 6097, 6099, 
6101, 6108, 6112, 6116, 6119, 6120, 6122, 6123, 6125, 6134, 6135, 
6138, 6141, 6145, 6147, 6198, 6233, 6217, 6258, 6161, 6242, 6218, 
6323, 6178, 6279, 6476, 6514, 6262, 6321, 6460, 6308, 6224, 6205, 
6208, 6302, 6195, 6153, 6532, 6500, 6492, 6240, 6457, 6273, 6422, 
6367, 6318, 6490, 6228, 6496, 6227, 6243, 6414, 6415, 6197, 6267, 
6306, 6177, 6155, 6260, 6459, 6264, 6154, 6170, 6263, 6304, 6259, 
6171, 6202, 6292, 6269, 6481, 6322, 6493, 6526, 6519, 6486, 6226, 
6169, 6450, 6445, 6261, 6438, 6252, 6468, 6220, 6505, 6299, 6193, 
6149, 6317, 6222, 6189, 6394, 6231, 6553, 6241, 6164, 6234, 6158, 
6216, 6375, 6168, 6452, 6265, 6537, 6369, 6294, 6488, 6214, 6291, 
6191, 6183, 6211, 6276, 6437, 6199, 6472, 6335, 6245, 6489, 6448, 
6504, 6506, 6347, 6253, 6163, 6316, 6502, 6246, 6179, 6473, 6282, 
6510, 6482, 6192, 6196, 6275, 6527, 6186, 6439, 6475, 6533, 6289, 
6503, 6298, 6436, 6225, 6376), sexo_s1 = structure(c(1, 0, 0, 
1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 
1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 
1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 
0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 
1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0,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, 60, 60, 
62, 65, 71, 70, 72, 70, 69, 73, 70, 61, 64, 56, 68, 74, 73, 67, 
68, 65, 67, 67, 70, 63, 61, 66, 72, 61, 61, 63, 65, 68, 67, 66, 
68, 63, 74, 71, 57, 62, 70, 74, 61, 61, 59, 62, 65, 67, 59, 65, 
68, 65, 65, 60, 69, 71, 65, 55, 63, 63, 61, 64, 71, 63, 60, 72, 
62, 64, 70, 71, 71, 64, 64, 64, 71, 69, 55, 65, 64, 72, 64, 71, 
69, 68, 75, 70, 72, 67, 60, 71, 60, 57, 65, 64, 66, 56, 57, 72, 
64, 74, 67, 67, 60, 61, 66, 69, 72, 75, 60, 68, 66, 64, 62, 68, 
68, 66, 67, 63, 69, 66, 65, 61, 56, 67, 63, 62, 68, 63, 64, 58, 
72, 70, 70, 63, 63, 75, 65, 66, 64, 65, 71, 64, 67, 70, 61, 72, 
71, 74, 60, 65, 75, 60, 58, 65, 58, 71, 69, 64, 75, 60, 64, 64, 
66, 67, 66, 60, 64, 60, 57, 61, 63, 63, 70, 73, 71, 63, 66, 67, 
61, 73, 68, 66, 63, 60, 64, 69, 66, 69, 60, 62, 62, 63, 63, 73, 
58, 69, 55, 63, 60, 64, 66, 60, 63, 63, 61, 66, 60, 65, 59, 62, 
72, 67, 68, 68, 61, 69, 70, 72, 60, 70, 61, 70, 65, 69, 72, 74, 
58, 63, 63, 74, 66, 65, 66, 61, 66, 60, 63, 66, 72, 69, 70, 63, 
66, 60, 67, 62, 57, 71, 63, 57, 58, 66, 67, 65, 60, 62, 61, 68, 
70, 57, 62, 68, 67, 65, 63, 67, 65, 63, 62, 70, 61, 59, 64, 72, 
67, 59, 67, 66, 64, 69, 70, 68, 74, 60, 63, 69, 68, 61, 61, 61, 
61, 63, 66, 68, 68, 72, 71, 62, 69, 68, 70, 69, 62, 63, 62, 69, 
73, 58, 71, 71, 69, 62, 66, 69, 65, 69, 59, 58, 72, 62, 67, 62, 
66, 72, 56, 70, 70, 71, 59, 70, 61, 62, 69, 63, 68, 60, 55, 60, 
61, 63, 67, 68, 66, 67, 64, 71, 65, 69, 61, 63, 73, 62, 72, 70, 
63, 56, 62, 59, 68, 67, 68, 72, 58, 63, 62, 65, 70, 71, 67, 59, 
61, 69, 66, 71, 65, 68, 60, 68, 69, 63, 66, 72, 74, 62, 63, 74, 
63, 66, 60, 65, 58, 73, 73, 71, 58, 68, 61), peso1_v00 = c(71.3, 
106, 76.8, 69.9, 85.1, 83, 102.7, 110.3, 80, 74.6, 95.9, 99, 
103.2, 65, 81.2, 90.3, 82.4, 78, 66.7, 97.3, 85.3, 79.9, 73.2, 
109.6, 71.1, 91.5, 60, 68.2, 70.8, 76.8, 96, 75.4, 63.9, 118.7, 
76.3, 120.1, 80.6, 92.4, 82.6, 80.1, 79.6, 82, 86.2, 90.4, 57.8, 
66.3, 63.7, 109.7, 103.4, 85, 77.6, 96.8, 92.5, 76.9, 99.5, 78.6, 
95.5, 89.3, 90.4, 70.1, 96.2, 75, 72.5, 67.1, 82.7, 82.8, 104.4, 
113.2, 78, 65.5, 123.5, 98.9, 78.7, 90.7, 106.6, 72, 84.2, 91, 
71.6, 93.4, 105.4, 122, 87.6, 86.4, 68, 85.5, 91.3, 66, 85.8, 
103.4, 98.7, 94.8, 83, 83.8, 92.8, 77.7, 66, 92.6, 98.3, 85.4, 
81.2, 107, 132.5, 108.2, 112.4, 102, 88.9, 93.1, 74.8, 90.6, 
74.4, 90, 101.8, 94.5, 86.5, 95.8, 84, 95.5, 76.7, 78.4, 72.6, 
76.2, 97.9, 85.5, 129, 88.9, 92.5, 85.4, 94.2, 102.1, 80.5, 80.5, 
105.7, 75.6, 102.5, 70.5, 105.5, 76.3, 101, 105.2, 83.5, 93.7, 
90.9, 107.5, 98, 77.5, 103.1, 91.3, 72.1, 103.7, 91.6, 81.6, 
92.4, 86.5, 75, 77.9, 102.5, 98, 82.1, 86.5, 77.5, 81.9, 112, 
91.2, 97.4, 86.5, 70, 82, 76.7, 87.8, 104.1, 71.1, 84.4, 93.5, 
76.8, 91.5, 65.3, 94.5, 88.3, 86.8, 65.2, 88.2, 66.5, 74, 84.1, 
85, 101.2, 85.3, 68.5, 91.5, 89, 81.8, 85, 86, 111.4, 98.8, 90, 
84.2, 62.7, 95, 85.8, 115.4, 76.2, 93.8, 107, 89.8, 101.5, 88, 
88.2, 103.8, 78.2, 101, 80.5, 69.4, 85.6, 79.5, 110.2, 84.8, 
99.8, 110.9, 69.7, 93.3, 66.7, 97.5, 82.4, 73.7, 80.2, 81.1, 
73, 101.6, 93.6, 76, 103.2, 77.5, 88.8, 65.7, 117, 82.5, 76.2, 
74.2, 91.9, 98.5, 106.5, 78.2, 85.1, 100.7, 79.2, 67.1, 70, 94.4, 
91.5, 91.6, 87.1, 91.8, 95.5, 125.9, 110.8, 95.3, 102.9, 116.4, 
91.1, 87.9, 78.6, 72, 108.2, 82.7, 117.2, 88.7, 110.1, 78.2, 
83.1, 83, 88.2, 107.5, 90.7, 73.1, 98.8, 100.1, 88.9, 107, 100.7, 
90, 82.2, 87.3, 80.2, 82.5, 107.9, 92.5, 89, 79.1, 99.5, 110.8, 
72.7, 107.7, 127.6, 92.9, 66.8, 91.6, 97, 94.5, 99, 94.9, 77, 
97.2, 90.7, 75, 114.6, 78.4, 85.6, 76.8, 88, 80.8, 98, 78.9, 
82.5, 73.7, 79, 119.8, 86.6, 78.7, 65.4, 74.5, 82.1, 90.9, 81.5, 
89.9, 90, 95.9, 77.3, 109, 71.9, 93, 57.9, 88.3, 93.4, 99.8, 
95, 75.8, 88.2, 78.4, 83.1, 85, 87.7, 88.8, 92.2, 78.8, 93.2, 
80.2, 76.8, 115.5, 93.4, 86.5, 70.3, 98.2, 91, 80.2, 88.4, 83, 
68, 72.8, 80.9, 102.5, 90.3, 83.7, 70.1, 115.6, 62, 86.7, 92.6, 
97.8, 75.1, 88.2, 110.9, 83, 101, 92.5, 94.2, 72.5, 70.5, 94.6, 
87.5, 75.2, 85.3, 69.8, 80.4, 70, 92.5, 88.5, 81.7, 105, 106.2, 
91.3, 110.2, 84.7, 95.8, 96.6, 90.5, 69.5, 98, 71, 137.5, 101.1, 
73.5, 64.8, 101.5, 85.1, 80.2), cintura1_v00 = c(105, 124, 104, 
100.5, 114, 100.5, 120.5, 132, 109, 101.5, 113, 123, 114, 95, 
102, 115, 117, 105.5, 89, 109, 104, 108.5, 102.5, 122.5, 95.4, 
119, 94, 96, 98.3, 100, 119.2, 102.8, 96, 136.2, 109.5, 132, 
103, 113, 98.5, 106.8, 117.5, 102.3, 102, 116, 94, 94.3, 93.2, 
127, 119, 96.5, 105.5, 113.5, 105.2, 112.8, 116.5, 102, 126, 
114.5, 114, 103, 108, 107, 104, 101, 110, 110, 125, 128, 106, 
97, 127.5, 118, 112, 104, 126.5, 107, 107, 109.5, 104, 107, 123, 
128.5, 123, 109.5, 99, 102.5, 109, 97, 108, 120, 113.5, 123, 
114.5, 105, 107, 106, 97, 115, 110.5, 109, 104.5, 129, 139, 120, 
121, 119, 108, 116.5, 104, 111.5, 100, 102, 117, 111, 116.5, 
124, 117, 112, 96, 104, 92, 110, 112.5, 110, 140, 119.5, 116, 
104, 114, 114, 116, 106.5, 116, 108, 114.5, 101.5, 116, 100, 
116, 116.5, 108.5, 113, 119, 116, 118, 105, 122, 121.5, 92.5, 
124.5, 115.5, 110, 116, 106, 100, 106.5, 126.5, 123, 104, 98, 
94, 115, 121.5, 107.5, 111.5, 102.5, 101, 106.5, 103, 101, 120.5, 
117, 104.5, 116, 103, 112, 96, 118.5, 108.5, 107, 102.5, 106, 
103, 105.5, 97.5, 103, 116.5, 114.5, 94, 112, 113.5, 110, 104, 
113, 124, 112, 114.5, 113.4, 90, 114, 106, 123, 106.5, 117, 116.5, 
107.5, 115, 103, 103, 118, 98, 103.5, 112.5, 95, 106, 103, 114, 
113, 122, 126, 102.5, 117, 85, 115, 100.2, 106, 107.5, 110, 102.7, 
126.3, 111.6, 103, 125, 107.7, 112, 91.5, 127.5, 117.7, 101, 
104.5, 117, 121.5, 130.7, 105.2, 117.2, 116.2, 109, 97, 98, 115, 
116, 107.5, 122, 116.7, 116.8, 131.8, 118.5, 115.5, 123.2, 122.6, 
115, 115, 113.2, 101.5, 119, 112, 134, 102, 131, 98, 110, 110, 
119, 126, 113.5, 102.5, 118.5, 119, 120, 121, 116.5, 114.5, 100, 
106.5, 104.5, 113, 128, 118, 107.5, 103, 125.5, 133, 103.5, 121, 
128, 115, 93.5, 107, 118.5, 110, 107, 110, 98, 112.5, 114.5, 
96, 130, 104, 106, 104, 103, 119, 132, 105.5, 106.5, 98, 109, 
135, 119.5, 104, 92, 106, 105.5, 107, 107, 113, 106, 104.5, 104, 
115.5, 104.5, 112, 94, 107.5, 110, 108, 113, 112.5, 120, 105, 
110, 112, 124.5, 116, 107, 105, 111.5, 108, 101.5, 129.5, 111, 
106, 102, 119.5, 113, 111, 109, 109, 100, 101, 110, 113.5, 114.5, 
107, 94, 126, 90, 109, 111, 120, 109, 116, 125, 120, 112, 119, 
114.5, 104.5, 90, 114, 117, 110.2, 104.5, 100, 106, 109, 108, 
108, 106.5, 111, 110, 129.5, 127, 108, 121, 117.5, 114, 101.5, 
109, 102.5, 131, 125, 109, 94, 121, 113, 103), tasis2_e_v00 = c(138, 
151, 134, 164, 138, 156, 144, 137, 130, 146, 131, 139, 122, 156, 
141, 161, 137, 130, 152, 120, 154, 165, 138, 169, 147, 155, 152, 
138, 136, 144, 123, 154, 138, 137, 123, 139, 145, 146, 145, 115, 
123, 137, 146, 121, 145, 109, 130, 138, 137, 123, 146, 131, 131, 
123, 123, 131, 145, 137, 146, 139, 160, 138, 109, 138, 178, 146, 
130, 130, 138, 147, 145, 138, 154, 144, 139, 136, 138, 149, 123, 
138, 130, 147, 154, 154, 122, 135, 139, 140, 146, 129, 145, 156, 
137, 116, 161, 146, 154, 167, 138, 146, 138, 137, 126, 129, 128, 
123, 138, 136, 121, 154, 146, 139, 138, 137, 148, 131, 146, 137, 
149, 138, 173, 147, 130, 156, 153, 148, 152, 114, 124, 149, 146, 
138, 131, 161, 143, 130, 155, 131, 131, 131, 144, 138, 146, 132, 
139, 146, 122, 130, 124, 154, 162, 114, 167, 138, 132, 130, 147, 
158, 153, 139, 145, 156, 140, 124, 131, 143, 146, 145, 123, 138, 
138, 144, 155, 124, 145, 149, 139, 138, 131, 145, 130, 144, 160, 
160, 139, 140, 123, 113, 123, 167, 157, 138, 113, 132, 146, 130, 
137, 168, 143, 115, 138, 139, 129, 136, 146, 145, 140, 115, 123, 
147, 145, 138, 138, 131, 135, 146, 131, 171, 147, 151, 176, 147, 
146, 124, 167, 123, 129, 149, 144, 146, 125, 123, 130, 145, 122, 
130, 146, 160, 131, 130, 139, 144, 126, 131, 106, 117, 153, 138, 
100, 146, 115, 137, 131, 161, 145, 161, 114, 123, 123, 127, 154, 
138, 146, 115, 140, 139, 122, 146, 162, 130, 118, 145, 158, 123, 
147, 161, 139, 147, 106, 138, 131, 138, 143, 138, 133, 129, 131, 
143, 136, 140, 147, 155, 146, 138, 146, 147, 134, 129, 145, 145, 
136, 147, 146, 139, 145, 175, 153, 152, 138, 139, 131, 123, 152, 
147, 124, 145, 154, 138, 148, 146, 146, 129, 147, 130, 164, 132, 
145, 132, 146, 133, 144, 136, 145, 148, 138, 146, 138, 113, 131, 
145, 146, 130, 146, 164, 138, 137, 139, 172, 130, 142, 165, 138, 
145, 131, 131, 139, 130, 122, 130, 147, 154, 122, 130, 121, 137, 
154, 132, 124, 153, 139, 146, 154, 138, 125, 124, 137, 147, 122, 
145, 131, 183, 146, 115, 138, 143, 145, 149, 132, 152, 130, 163, 
130, 146, 144, 117, 131, 121, 146, 130, 147, 169, 138, 133, 149, 
123, 161, 130), tadias2_e_v00 = c(76, 71, 59, 63, 84, 67, 79, 
76, 72, 88, 50, 65, 71, 60, 59, 78, 79, 64, 67, 53, 81, 93, 80, 
103, 76, 77, 71, 79, 63, 80, 49, 87, 68, 69, 69, 72, 75, 88, 
79, 69, 68, 67, 76, 75, 71, 67, 63, 76, 77, 60, 68, 83, 85, 71, 
84, 65, 79, 59, 81, 73, 66, 72, 74, 68, 65, 80, 65, 96, 77, 82, 
88, 60, 79, 78, 85, 73, 76, 63, 91, 72, 69, 84, 76, 80, 56, 84, 
96, 83, 80, 84, 71, 89, 72, 77, 97, 81, 60, 76, 87, 80, 88, 87, 
73, 71, 80, 78, 76, 75, 67, 73, 88, 69, 88, 83, 58, 65, 57, 71, 
81, 75, 70, 87, 84, 82, 72, 86, 73, 71, 65, 82, 80, 68, 92, 72, 
79, 79, 94, 87, 77, 64, 78, 85, 65, 78, 77, 81, 76, 68, 62, 77, 
95, 78, 89, 78, 87, 68, 82, 65, 75, 81, 64, 57, 93, 66, 81, 80, 
88, 84, 54, 72, 81, 69, 98, 76, 79, 79, 77, 84, 81, 65, 69, 76, 
74, 75, 78, 74, 68, 68, 72, 85, 93, 72, 68, 68, 92, 71, 75, 74, 
91, 81, 80, 78, 63, 71, 80, 75, 82, 61, 65, 81, 79, 63, 72, 59, 
89, 72, 58, 89, 82, 88, 110, 81, 72, 80, 89, 72, 76, 82, 78, 
79, 81, 76, 82, 56, 75, 55, 89, 75, 76, 63, 68, 79, 67, 61, 60, 
61, 76, 71, 50, 68, 68, 63, 64, 62, 79, 81, 68, 62, 65, 78, 93, 
82, 80, 72, 85, 69, 84, 68, 74, 80, 71, 84, 91, 57, 90, 71, 78, 
61, 46, 82, 72, 81, 78, 60, 79, 71, 76, 60, 79, 66, 73, 66, 84, 
85, 73, 86, 64, 67, 85, 79, 84, 88, 72, 66, 92, 78, 88, 69, 72, 
73, 65, 57, 90, 65, 49, 83, 80, 77, 90, 73, 80, 74, 78, 76, 81, 
81, 94, 74, 80, 73, 79, 82, 84, 83, 92, 65, 73, 58, 58, 83, 79, 
64, 80, 98, 79, 79, 78, 89, 76, 86, 95, 76, 79, 84, 73, 69, 69, 
68, 64, 101, 74, 68, 61, 75, 75, 73, 58, 77, 73, 74, 49, 91, 
72, 56, 66, 71, 77, 72, 80, 96, 94, 60, 65, 57, 55, 79, 65, 73, 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11, 10, 7, 9, 9, 6, 8, 3, 4, 
10, 6, 8, 7, 9, 4, 8, 11, 6, 9, 10, 10, 6, 10, 6, 9, 5, 7, 6, 
9, 7, 7, 9, 7, 6, 7, 2, 5, 4, 4, 5, 5, 7, 10, 5, 10, 8, 6, 10, 
4, 7, 10, 6, 10, 9, 7, 8, 7, 7, 10, 5, 6, 5, 9, 8, 8, 6, 5, 3, 
9, 5, 7, 5, 10, 9, 4, 7, 6, 13, 7, 3, 6, 6, 7, 4, 9, 9, 6, 5, 
10, 8, 10, 6, 11, 10), geaf_tot_v00 = c(2517.48, 2769.23, 97.9, 
5146.85, 664.34, 1557.11, 1678.32, 1300.7, 7574.83, 1678.32, 
3543.12, 3188.81, 2293.71, 111.89, 4755.24, 5687.65, 3153.85, 
2958.04, 2042.89, 1535.66, 1678.32, 1931.93, 432.63, 292.77, 
2331, 6834.5, 2530.54, 1272.73, 909.09, 1986.01, 559.44, 2321.68, 
3356.64, 559.44, 559.44, 86.71, 2097.9, 3384.62, 2349.65, 2713.29, 
839.16, 4755.24, 1622.38, 615.38, 1678.32, 395.34, 2937.06, 4382.28, 
2797.2, 2388.81, 8937.06, 1678.32, 2237.76, 5679.25, 3804.2, 
1678.32, 1818.18, 839.16, 4643.36, 2531.47, 6414.92, 5622.38, 
4895.1, 2377.62, 447.55, 1371.56, 1678.32, 0, 2834.5, 4335.66, 
455.01, 1398.6, 6293.71, 559.44, 2237.76, 839.16, 4965.03, 923.08, 
2517.48, 3482.52, 1958.04, 3356.64, 2937.06, 1608.39, 9860.14, 
2797.2, 2293.71, 6853.15, 5034.97, 5559.44, 1678.32, 2937.06, 
466.2, 1332.4, 1440.56, 83.92, 2517.48, 839.16, 839.16, 2013.99, 
3034.97, 251.75, 6433.57, 1930.07, 643.36, 839.16, 5902.1, 2834.5, 
3076.92, 3251.75, 4587.41, 93.24, 1076.92, 4895.1, 10349.65, 
3356.64, 3356.64, 839.16, 699.3, 5524.48, 13986.01, 0, 3524.48, 
1706.29, 2237.76, 3916.08, 279.72, 5995.34, 2517.48, 2536.13, 
2517.48, 895.1, 279.72, 2237.76, 2314.69, 581.82, 27.97, 1230.77, 
5118.88, 1818.18, 3076.92, 7160.84, 4191.14, 3636.36, 1461.54, 
839.16, 1118.88, 1678.32, 447.55, 2382.28, 3356.64, 895.1, 3468.53, 
4055.94, 1398.6, 3121.68, 186.48, 7370.63, 587.41, 671.33, 1980.42, 
4475.52, 1818.18, 3356.64, 419.58, 1601.4, 1202.8, 1258.74, 1300.7, 
1433.57, 55.94, 335.66, 1048.95, 2657.34, 350.58, 559.44, 6013.99, 
1048.95, 951.05, 1678.32, 372.96, 5734.27, 671.33, 3650.35, 223.78, 
7160.84, 1706.29, 559.44, 2853.15, 7780.89, 6951.05, 5601.4, 
4335.66, 1678.32, 1006.99, 3216.78, 3475.52, 3104.9, 3118.88, 
2769.23, 6242.42, 2256.41, 2517.48, 0, 1501.17, 6937.06, 4944.06, 
5524.48, 923.08, 1678.32, 3776.22, 7496.5, 1370.63, 2797.2, 615.38, 
4755.24, 279.72, 3356.64, 139.86, 671.33, 895.1, 9097.44, 8053.15, 
139.86, 3174.83, 1444.29, 1594.41, 863.4, 3358.51, 1670.86, 1090.91, 
1454.55, 2452.21, 3084.38, 1678.32, 231, 2517.48, 198.14, 4195.8, 
2517.48, 1678.32, 1678.32, 5927.27, 3776.22, 2265.73, 4128.21, 
2517.48, 2101.63, 7272.73, 1678.32, 1734.27, 3776.22, 167.83, 
2386.01, 1678.32, 4219.11, 1659.67, 2800.93, 1286.71, 4055.94, 
559.44, 1398.6, 2489.51, 3184.15, 1188.81, 1286.71, 671.33, 2713.29, 
5874.13, 3412.59, 1468.53, 1525.41, 0, 339.39, 4820.51, 559.44, 
157.34, 1118.88, 111.89, 839.16, 783.22, 2144.52, 1491.84, 8400, 
2601.4, 923.08, 2279.72, 2055.94, 6853.15, 1822.84, 1678.32, 
10069.93, 2601.4, 1384.62, 3356.64, 4475.52, 993.94, 391.61, 
1454.55, 1146.85, 5734.27, 895.1, 2937.06, 839.16, 1832.17, 839.16, 
1174.83, 993.01, 1118.88, 4475.52, 1538.46, 6293.71, 0, 2741.26, 
1976.69, 1734.27, 10209.79, 1324.01, 111.89, 1720.28, 3398.6, 
0, 6881.12, 335.66, 4461.54, 3412.59, 1070.4, 5594.41, 3356.64, 
6489.51, 1846.15, 0, 2377.62, 4615.38, 3916.08, 3356.64, 419.58, 
839.16, 3020.98, 3832.17, 839.16, 6153.85, 419.58, 302.1, 1685.78, 
1398.6, 83.92, 2592.07, 839.16, 0, 3356.64, 0, 69.93, 1657.34, 
1995.34, 419.58, 1557.11, 3860.14, 3566.43, 4405.59, 5930.07, 
547.79, 629.37, 1441.49, 1607.46, 1135.66, 3524.48, 4377.62, 
279.72, 0, 5594.41, 2573.43, 9006.99, 335.66, 1762.24, 2601.4, 
8146.85, 3524.48, 2237.76, 2685.31, 1335.66, 1153.85, 1118.88, 
1258.74, 419.58, 3636.36, 4160.84, 1678.32, 2212.12, 1398.6, 
2517.48, 5594.41, 2517.48, 4979.02, 783.22, 4657.34, 559.44, 
559.44, 1958.04, 2797.2, 773.89, 839.16, 6228.44, 2256.41, 419.58, 
1678.32, 3286.71)), row.names = c(NA, 407L), class = "data.frame")

The columns

vars<-c( "peso1_v00", "cintura1_v00", "tasis2_e_v00", "tadias2_e_v00", "p17_total_v00", "geaf_tot_v00" )

Then I have done the loop

for (v in vars) {
  print(
    boxplot(df[, v], main = v)
    
  )
  
}

Then, there are generated several boxplots in the viewer. The problem is with my real database I have multiple plots, and I am looking for something to save it all at once. The solutions proposed in previous threads are not working

Thanks for the hel in advance

Hello,

Your best will be something like the below:

library(ggplot2)
data("iris")

# list of values to loop over
uniq_species = unique(iris$Species)


# Loop

for (i in uniq_species) {
  
  temp_plot = ggplot(data= subset(iris, Species == i)) + 
    geom_point(size=3, aes(x=Petal.Length, y=Petal.Width )) +
    ggtitle(i)
  
  ggsave(temp_plot, file=paste0("plot_", i,".png"), width = 14, height = 10, units = "cm")
}

Created on 2021-10-22 by the reprex package (v2.0.1)

ggsave will save the last plot in the viewer and this will be your best way to generate -> save -> generate etc. There is no other way I know of where you can "query" all the plots in "viewer" and save them. ggsave is the default way to do this. Let me know if this helps?

base plots must be 'recorded' to store them in a variable and can be replayed later.


library(dplyr)
 library(purrr)
 
 (to_do <- select(iris,
                 where(is.numeric)) %>%
   names)
 
 
 list_of_box_plots <- map(to_do,
     ~{ 
       boxplot(iris[[.x]],main=.x)
       recordPlot()
     })
 
 #clear the plots display of Rstudio
 dev.off()
 
 #get the plots back
 walk(list_of_box_plots,~{
   plot.new()
   replayPlot(.x)})
1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.