Interpolation and estimation of data in R - r
Here are my data showing the cardiopulmonary evolution during an acute exercise with gaz exchange analysis. As we can see, when I report data according the relative percentage of peak power (percent_power), the percentage doesn't correspond between each individuals, because, of course, everyone has a different peak.
Then, I would like to create an interpolation for each individual to estimate specific percentages (e.g. 25%, 50%, 75%) for each individual, and put in a column. Consequently, each variable should be estimated as well and should correspond to the new estimated 25, 50, 75 % of percent_power.
Thank you very much all for your help,
id power training hr fr VE absVO2 VCO2 PETCO2 VES QC IC WCI RVSi RVS VTD FE body_mass percent_absVO2 percent_power relVO2 percent_relVO2 group temps
1 AC12-PRD-C1 25 linear 88.75 22.75 22.75 0.73900 0.66700 39.2925 88.650 8.025 3.975 4.825 1768.75 876.00 143.025 62.050 84.0 49.34068 21.73913 8.797619 49.34068 CHD 1
2 AC12-PRD-C1 40 linear 93.25 23.00 23.75 0.81975 0.71500 39.6200 87.375 8.050 3.975 4.825 1759.50 871.75 141.625 61.725 84.0 54.73210 34.78261 9.758929 54.73210 CHD 1
3 AC12-PRD-C1 55 linear 99.75 22.75 26.75 0.95125 0.85400 41.4100 93.375 9.175 4.550 5.525 1540.50 763.00 150.325 62.100 84.0 63.51193 47.82609 11.324405 63.51193 CHD 1
4 AC12-PRD-C1 70 linear 109.75 23.00 32.50 1.07525 1.04700 42.0150 93.825 10.025 4.925 6.000 1414.25 700.50 145.750 64.375 84.0 71.79102 60.86957 12.800595 71.79102 CHD 1
5 AC12-PRD-C1 85 linear 118.75 22.75 39.50 1.19900 1.25125 41.8425 97.375 11.225 5.575 6.750 1260.75 624.50 148.975 65.325 84.0 80.05341 73.91304 14.273810 80.05341 CHD 1
6 AC12-PRD-C1 100 linear 127.00 26.00 48.25 1.34575 1.51850 41.0950 100.900 12.550 6.225 7.525 1127.75 558.75 154.225 65.475 84.0 89.85144 86.95652 16.020833 89.85144 CHD 1
7 AC12-PRD-C1 115 linear 135.75 28.00 55.75 1.49775 1.76025 40.7275 104.475 13.950 6.875 8.375 1014.00 502.25 157.975 66.250 84.0 100.00000 100.00000 17.830357 100.00000 CHD 1
8 AC12-PRD-C2 25 linear 84.25 20.50 20.75 0.67625 0.59950 38.9575 102.700 8.650 4.275 5.575 1775.00 879.50 216.450 48.350 84.8 40.10378 17.24138 7.974646 40.10378 CHD 2
9 AC12-PRD-C2 40 linear 89.25 20.50 23.25 0.73350 0.66225 38.5500 111.625 9.725 4.800 6.250 1567.75 776.75 217.800 51.825 84.8 43.49889 27.58621 8.649764 43.49889 CHD 2
10 AC12-PRD-C2 55 linear 96.25 22.25 26.75 0.83550 0.77500 38.3350 101.300 9.325 4.625 6.000 1619.75 802.75 202.700 50.350 84.8 49.54781 37.93103 9.852594 49.54781 CHD 2
11 AC12-PRD-C2 70 linear 102.25 21.75 32.50 1.06250 1.01550 39.6525 103.550 10.350 5.125 6.625 1459.00 723.00 194.050 53.675 84.8 63.00964 48.27586 12.529481 63.00964 CHD 2
12 AC12-PRD-C2 85 linear 110.75 22.25 37.75 1.18075 1.19225 40.1300 100.825 10.650 5.275 6.825 1424.00 705.25 194.250 51.900 84.8 70.02224 58.62069 13.923939 70.02224 CHD 2
13 AC12-PRD-C2 100 linear 118.25 23.00 42.75 1.35100 1.40300 41.1500 108.950 12.375 6.100 7.950 1225.50 606.75 197.325 55.175 84.8 80.11861 68.96552 15.931604 80.11861 CHD 2
14 AC12-PRD-C2 115 linear 129.25 24.75 51.25 1.50650 1.65650 40.7575 107.625 13.275 6.550 8.525 1133.50 561.50 201.225 53.525 84.8 89.34025 79.31034 17.765330 89.34025 CHD 2
15 AC12-PRD-C2 130 linear 136.25 26.50 58.75 1.57325 1.83200 39.6750 108.925 14.375 7.125 9.250 1045.75 518.25 196.025 55.675 84.8 93.29874 89.65517 18.552476 93.29874 CHD 2
16 AC12-PRD-C2 145 linear 147.50 29.75 70.00 1.68625 2.07350 38.1600 104.875 15.025 7.450 9.600 1010.75 500.75 185.400 56.825 84.8 100.00000 100.00000 19.885024 100.00000 CHD 2
17 AL13-PRD-C1 25 nonlinear 69.50 16.50 24.00 0.66125 0.58050 31.2275 101.825 7.175 3.500 4.450 2126.50 1037.25 220.850 48.550 85.5 41.36691 19.23077 7.733918 41.36691 CHD 1
18 AL13-PRD-C1 40 nonlinear 73.00 17.50 26.50 0.74850 0.66425 32.1025 107.850 7.775 3.775 4.850 1942.00 947.25 242.825 48.000 85.5 46.82515 30.76923 8.754386 46.82515 CHD 1
19 AL13-PRD-C1 55 nonlinear 83.25 15.50 29.00 0.85500 0.79425 33.6650 110.250 9.075 4.375 5.650 1706.00 832.50 233.500 47.325 85.5 53.48764 42.30769 10.000000 53.48764 CHD 1
20 AL13-PRD-C1 70 nonlinear 93.75 16.00 36.50 0.98450 0.99925 34.5325 114.650 10.425 5.075 6.525 1462.00 713.25 233.075 49.175 85.5 61.58899 53.84615 11.514620 61.58899 CHD 1
21 AL13-PRD-C1 85 nonlinear 104.50 16.00 44.75 1.14950 1.23475 34.4225 120.650 12.150 5.925 7.550 1249.25 609.25 233.575 51.775 85.5 71.91117 65.38462 13.444444 71.91117 CHD 1
22 AL13-PRD-C1 100 nonlinear 114.25 19.25 55.25 1.34650 1.48375 33.1800 115.250 12.775 6.275 7.975 1178.25 574.75 220.375 52.350 85.5 84.23522 76.92308 15.748538 84.23522 CHD 1
23 AL13-PRD-C1 115 nonlinear 125.25 20.75 63.75 1.45100 1.65775 32.6450 117.500 14.100 6.875 8.825 1095.25 534.25 236.575 50.200 85.5 90.77260 88.46154 16.970760 90.77260 CHD 1
24 AL13-PRD-C1 130 nonlinear 136.25 24.75 78.00 1.59850 1.89075 30.9000 119.150 15.575 7.600 9.700 968.25 472.25 231.075 51.600 85.5 100.00000 100.00000 18.695906 100.00000 CHD 1
25 AL13-PRD-C2 25 nonlinear 60.25 15.75 19.00 0.56950 0.46550 32.2575 154.625 9.450 4.700 6.075 1597.75 794.75 348.975 44.850 82.4 30.83378 15.62500 6.911408 30.83378 CHD 2
26 AL13-PRD-C2 40 nonlinear 63.25 14.25 19.50 0.63175 0.52325 33.5700 143.225 9.275 4.625 5.975 1631.75 811.50 326.325 44.575 82.4 34.20411 25.00000 7.666869 34.20411 CHD 2
27 AL13-PRD-C2 55 nonlinear 72.75 15.75 25.00 0.82600 0.69925 34.4600 147.350 10.175 5.075 6.525 1497.25 744.75 312.475 47.950 82.4 44.72117 34.37500 10.024272 44.72117 CHD 2
28 AL13-PRD-C2 70 nonlinear 79.00 15.50 30.75 0.94525 0.86850 34.9675 153.575 11.925 5.925 7.675 1257.00 625.25 271.525 56.625 82.4 51.17759 43.75000 11.471481 51.17759 CHD 2
29 AL13-PRD-C2 85 nonlinear 88.25 16.00 37.50 1.15050 1.08025 35.6175 155.200 13.325 6.625 8.550 1127.00 560.50 282.300 54.975 82.4 62.29020 53.12500 13.962379 62.29020 CHD 2
30 AL13-PRD-C2 100 nonlinear 99.00 16.75 44.75 1.29925 1.31475 35.6475 154.150 14.775 7.325 9.500 1030.75 512.50 285.350 54.500 82.4 70.34380 62.50000 15.767597 70.34380 CHD 2
31 AL13-PRD-C2 115 nonlinear 107.00 18.00 50.00 1.39775 1.45600 36.0325 161.000 16.675 8.300 10.725 898.00 446.50 282.850 57.175 82.4 75.67677 71.87500 16.962985 75.67677 CHD 2
32 AL13-PRD-C2 130 nonlinear 118.50 21.00 61.50 1.55100 1.73675 34.8775 162.300 18.300 9.100 11.750 815.75 405.75 276.700 58.700 82.4 83.97401 81.25000 18.822816 83.97401 CHD 2
33 AL13-PRD-C2 145 nonlinear 128.25 24.25 74.75 1.71275 1.99100 33.3300 161.025 19.925 9.900 12.800 749.50 372.75 267.875 60.175 82.4 92.73146 90.62500 20.785801 92.73146 CHD 2
34 AL13-PRD-C2 160 nonlinear 142.50 29.00 90.50 1.84700 2.21650 30.9325 154.750 20.925 10.425 13.425 715.50 355.75 272.250 57.100 82.4 100.00000 100.00000 22.415049 100.00000 CHD 2
Related
How to average and estimate data in R
I have this data: id power training hr percent_absVO2 percent_power relVO2 percent_relVO2 1 AC12-PRD-C1 25 linear 88.75 49.34068 21.73913 8.797619 49.34068 2 AC12-PRD-C1 40 linear 93.25 54.73210 34.78261 9.758929 54.73210 3 AC12-PRD-C1 55 linear 99.75 63.51193 47.82609 11.324405 63.51193 4 AC12-PRD-C1 70 linear 109.75 71.79102 60.86957 12.800595 71.79102 5 AC12-PRD-C1 85 linear 118.75 80.05341 73.91304 14.273810 80.05341 6 AC12-PRD-C1 100 linear 127.00 89.85144 86.95652 16.020833 89.85144 7 AC12-PRD-C1 115 linear 135.75 100.00000 100.00000 17.830357 100.00000 8 AC12-PRD-C2 25 linear 84.25 40.10378 17.24138 7.974646 40.10378 9 AC12-PRD-C2 40 linear 89.25 43.49889 27.58621 8.649764 43.49889 10 AC12-PRD-C2 55 linear 96.25 49.54781 37.93103 9.852594 49.54781 11 AC12-PRD-C2 70 linear 102.25 63.00964 48.27586 12.529481 63.00964 12 AC12-PRD-C2 85 linear 110.75 70.02224 58.62069 13.923939 70.02224 13 AC12-PRD-C2 100 linear 118.25 80.11861 68.96552 15.931604 80.11861 14 AC12-PRD-C2 115 linear 129.25 89.34025 79.31034 17.765330 89.34025 15 AC12-PRD-C2 130 linear 136.25 93.29874 89.65517 18.552476 93.29874 16 AC12-PRD-C2 145 linear 147.50 100.00000 100.00000 19.885024 100.00000 17 AL13-PRD-C1 25 nonlinear 69.50 41.36691 19.23077 7.733918 41.36691 18 AL13-PRD-C1 40 nonlinear 73.00 46.82515 30.76923 8.754386 46.82515 19 AL13-PRD-C1 55 nonlinear 83.25 53.48764 42.30769 10.000000 53.48764 20 AL13-PRD-C1 70 nonlinear 93.75 61.58899 53.84615 11.514620 61.58899 21 AL13-PRD-C1 85 nonlinear 104.50 71.91117 65.38462 13.444444 71.91117 22 AL13-PRD-C1 100 nonlinear 114.25 84.23522 76.92308 15.748538 84.23522 23 AL13-PRD-C1 115 nonlinear 125.25 90.77260 88.46154 16.970760 90.77260 24 AL13-PRD-C1 130 nonlinear 136.25 100.00000 100.00000 18.695906 100.00000 25 AL13-PRD-C2 25 nonlinear 60.25 30.83378 15.62500 6.911408 30.83378 26 AL13-PRD-C2 40 nonlinear 63.25 34.20411 25.00000 7.666869 34.20411 27 AL13-PRD-C2 55 nonlinear 72.75 44.72117 34.37500 10.024272 44.72117 28 AL13-PRD-C2 70 nonlinear 79.00 51.17759 43.75000 11.471481 51.17759 29 AL13-PRD-C2 85 nonlinear 88.25 62.29020 53.12500 13.962379 62.29020 30 AL13-PRD-C2 100 nonlinear 99.00 70.34380 62.50000 15.767597 70.34380 31 AL13-PRD-C2 115 nonlinear 107.00 75.67677 71.87500 16.962985 75.67677 32 AL13-PRD-C2 130 nonlinear 118.50 83.97401 81.25000 18.822816 83.97401 33 AL13-PRD-C2 145 nonlinear 128.25 92.73146 90.62500 20.785801 92.73146 34 AL13-PRD-C2 160 nonlinear 142.50 100.00000 100.00000 22.415049 100.00000 As you can see, not everyone has the same percent_power value. I would like to make everyone one the same increment according the percent_power column. For example, I would like to get 25 %, 50 %, 75 %, and 100 %. That means that the value has to be estimated if I understand well. Here is an example for only 2 patients of what I would expect. Values in the other column have to be estimated if the exact percent_power doesn't exist. id power training hr percent_absVO2 percent_power relVO2 percent_relVO2 1 AC12-PRD-C1 25 linear 88.75 49.34068 25.00000 8.797619 49.34068 2 AC12-PRD-C1 55 linear 99.75 63.51193 50.00000 11.324405 63.51193 3 AC12-PRD-C1 85 linear 118.75 80.05341 75.00000 14.273810 80.05341 4 AC12-PRD-C1 115 linear 135.75 100.00000 100.00000 17.830357 100.00000 5 AC12-PRD-C2 40 linear 89.25 43.49889 25.00000 8.649764 43.49889 6 AC12-PRD-C2 70 linear 102.25 63.00964 50.00000 12.529481 63.00964 7 AC12-PRD-C2 115 linear 129.25 89.34025 75.00000 17.765330 89.34025 16 AC12-PRD-C2 145 linear 147.50 100.00000 100.00000 19.885024 100.00000 Thank you for your help !
Your question is not well defined, you want us to predict multiple variables, but you do not tell us how, which is crucial. There are infinitely many ways in which you could "predict" these missing values. For ex. your variables "percent" are limited within 0 and 100, which you have to include in your prediction, or you will get nonsense results. Having said that, I will do just that and predict all these variables using a simple linear model, which assumes a linear relationship between all your numeric variables and percent_power. First create a linear model to make your predictions mod=lm(cbind(power,hr,percent_absVO2,relVO2,percent_relVO2)~percent_power*id+training,data=df) then create your dataset with all the combinations that you want to predict tst=setNames( data.frame( expand.grid(unique(df[,"id"]),unique(df[,"training"]),seq(25,100,25)) ) ,c("id","training","percent_power") ) and then predict cbind( tst, predict(mod,tst) ) id training percent_power power hr percent_absVO2 relVO2 1 AC12-PRD-C1 linear 25 28.75 88.08482 49.30491 8.791242 2 AC12-PRD-C2 linear 25 36.25 86.88333 43.57464 8.664828 3 AL13-PRD-C1 linear 25 32.50 70.24554 42.60440 7.965278 4 AL13-PRD-C2 linear 25 40.00 63.65909 36.80735 8.250386 5 AC12-PRD-C1 nonlinear 25 28.75 88.08482 49.30491 8.791242 6 AC12-PRD-C2 nonlinear 25 36.25 86.88333 43.57464 8.664828 7 AL13-PRD-C1 nonlinear 25 32.50 70.24554 42.60440 7.965278 8 AL13-PRD-C2 nonlinear 25 40.00 63.65909 36.80735 8.250386 9 AC12-PRD-C1 linear 50 57.50 103.65774 65.64847 11.705357 10 AC12-PRD-C2 linear 50 72.50 106.05556 63.13669 12.554745 11 AL13-PRD-C1 linear 50 65.00 91.71230 61.50428 11.498782 12 AL13-PRD-C2 linear 50 80.00 88.20455 57.97911 12.996047 13 AC12-PRD-C1 nonlinear 50 57.50 103.65774 65.64847 11.705357 14 AC12-PRD-C2 nonlinear 50 72.50 106.05556 63.13669 12.554745 15 AL13-PRD-C1 nonlinear 50 65.00 91.71230 61.50428 11.498782 16 AL13-PRD-C2 nonlinear 50 80.00 88.20455 57.97911 12.996047 17 AC12-PRD-C1 linear 75 86.25 119.23065 81.99203 14.619473 18 AC12-PRD-C2 linear 75 108.75 125.22778 82.69873 16.444662 19 AL13-PRD-C1 linear 75 97.50 113.17907 80.40415 15.032285 20 AL13-PRD-C2 linear 75 120.00 112.75000 79.15088 17.741707 21 AC12-PRD-C1 nonlinear 75 86.25 119.23065 81.99203 14.619473 22 AC12-PRD-C2 nonlinear 75 108.75 125.22778 82.69873 16.444662 23 AL13-PRD-C1 nonlinear 75 97.50 113.17907 80.40415 15.032285 24 AL13-PRD-C2 nonlinear 75 120.00 112.75000 79.15088 17.741707 25 AC12-PRD-C1 linear 100 115.00 134.80357 98.33560 17.533588 26 AC12-PRD-C2 linear 100 145.00 144.40000 102.26077 20.334578 27 AL13-PRD-C1 linear 100 130.00 134.64583 99.30403 18.565789 28 AL13-PRD-C2 linear 100 160.00 137.29545 100.32264 22.487368 29 AC12-PRD-C1 nonlinear 100 115.00 134.80357 98.33560 17.533588 30 AC12-PRD-C2 nonlinear 100 145.00 144.40000 102.26077 20.334578 31 AL13-PRD-C1 nonlinear 100 130.00 134.64583 99.30403 18.565789 32 AL13-PRD-C2 nonlinear 100 160.00 137.29545 100.32264 22.487368 percent_relVO2 1 49.30491 2 43.57464 3 42.60440 4 36.80735 5 49.30491 6 43.57464 7 42.60440 8 36.80735 9 65.64847 10 63.13669 11 61.50428 12 57.97911 13 65.64847 14 63.13669 15 61.50428 16 57.97911 17 81.99203 18 82.69873 19 80.40415 20 79.15088 21 81.99203 22 82.69873 23 80.40415 24 79.15088 25 98.33560 26 102.26077 27 99.30403 28 100.32264 29 98.33560 30 102.26077 31 99.30403 32 100.32264 Note how the percents have gone over 100, which was to be expected, given our model.
When I got you correct, that is what you want. library(dplyr) df <- structure(list(id = c("AC12-PRD-C1", "AC12-PRD-C1", "AC12-PRD-C1", "AC12-PRD-C1", "AC12-PRD-C1", "AC12-PRD-C1", "AC12-PRD-C1", "AC12-PRD-C2", "AC12-PRD-C2", "AC12-PRD-C2", "AC12-PRD-C2", "AC12-PRD-C2", "AC12-PRD-C2", "AC12-PRD-C2", "AC12-PRD-C2", "AC12-PRD-C2", "AL13-PRD-C1", "AL13-PRD-C1", "AL13-PRD-C1", "AL13-PRD-C1", "AL13-PRD-C1", "AL13-PRD-C1", "AL13-PRD-C1", "AL13-PRD-C1", "AL13-PRD-C2", "AL13-PRD-C2", "AL13-PRD-C2", "AL13-PRD-C2", "AL13-PRD-C2", "AL13-PRD-C2", "AL13-PRD-C2", "AL13-PRD-C2", "AL13-PRD-C2" ), power = c(25, 40, 55, 70, 85, 100, 115, 25, 40, 55, 70, 85, 100, 115, 130, 145, 25, 40, 55, 70, 85, 100, 115, 130, 25, 40, 55, 70, 85, 100, 115, 130, 145), training = c("linear", "linear", "linear", "linear", "linear", "linear", "linear", "linear", "linear", "linear", "linear", "linear", "linear", "linear", "linear", "linear", "nonlinear", "nonlinear", "nonlinear", "nonlinear", "nonlinear", "nonlinear", "nonlinear", "nonlinear", "nonlinear", "nonlinear", "nonlinear", "nonlinear", "nonlinear", "nonlinear", "nonlinear", "nonlinear", "nonlinear"), hr = c(88.75, 93.25, 99.75, 109.75, 118.75, 127, 135.75, 84.25, 89.25, 96.25, 102.25, 110.75, 118.25, 129.25, 136.25, 147.5, 69.5, 73, 83.25, 93.75, 104.5, 114.25, 125.25, 136.25, 60.25, 63.25, 72.75, 79, 88.25, 99, 107, 118.5, 128.25), percent_absVO2 = c(49.34068, 54.7321, 63.51193, 71.79102, 80.05341, 89.85144, 100, 40.10378, 43.49889, 49.54781, 63.00964, 70.02224, 80.11861, 89.34025, 93.29874, 100, 41.36691, 46.82515, 53.48764, 61.58899, 71.91117, 84.23522, 90.7726, 100, 30.83378, 34.20411, 44.72117, 51.17759, 62.2902, 70.3438, 75.67677, 83.97401, 92.73146), percent_power = c(21.73913, 34.78261, 47.82609, 60.86957, 73.91304, 86.95652, 100, 17.24138, 27.58621, 37.93103, 48.27586, 58.62069, 68.96552, 79.31034, 89.65517, 100, 19.23077, 30.76923, 42.30769, 53.84615, 65.38462, 76.92308, 88.46154, 100, 15.625, 25, 34.375, 43.75, 53.125, 62.5, 71.875, 81.25, 90.625), relVO2 = c(8.797619, 9.758929, 11.324405, 12.800595, 14.273810, 16.020833, 17.830357, 7.974646, 8.649764, 9.852594, 12.529481, 13.923939, 15.931604, 17.765330, 18.552476, 19.885024, 7.733918, 8.754386, 10.000000, 11.514620, 13.444444, 15.748538, 16.970760, 18.695906, 6.911408, 7.666869, 10.024272, 11.471481, 13.962379, 15.767597, 16.962985, 18.822816, 20.785801), percent_relVO2 = c(49.34068, 54.7321, 63.51193, 71.79102, 80.05341, 89.85144, 100, 40.10378, 43.49889, 49.54781, 63.00964, 70.02224, 80.11861, 89.34025, 93.29874, 100, 41.36691, 46.82515, 53.48764, 61.58899, 71.91117, 84.23522, 90.7726, 100, 30.83378, 34.20411, 44.72117, 51.17759, 62.2902, 70.3438, 75.67677, 83.97401, 92.73146)), row.names = c(NA, -33L), class = c("tbl_df", "tbl", "data.frame")) df %>% dplyr::mutate(., percent_power = dplyr::case_when( percent_absVO2 < 25 ~ 0, percent_absVO2 < 50 ~ 25, percent_absVO2 < 75 ~ 50, percent_absVO2 < 100 ~ 75, TRUE ~ 100 ))
How to perform a polynomial equation and curve?
I have this dataframe: id power hr fr VE VO2 VCO2 PETCO2 percent_VO2 percent_power 1 BM06-PRD-S1 25 119.25 18.25 19.00 0.61675 0.58225 37.6425 48.87084 25.00000 2 BM06-PRD-S1 40 126.00 18.00 20.75 0.71700 0.65950 39.2175 56.81458 40.00000 3 BM06-PRD-S1 55 133.50 20.75 25.00 0.86275 0.82750 41.2150 68.36371 55.00000 4 BM06-PRD-S1 70 147.25 18.25 29.00 0.98575 1.04550 41.7050 78.11014 70.00000 5 BM06-PRD-S1 85 158.50 22.25 39.25 1.13000 1.30525 41.1425 89.54041 85.00000 6 BM06-PRD-S1 100 168.75 27.75 51.00 1.26200 1.61150 38.8925 100.00000 100.00000 7 CB19-PRD-S1 25 98.75 18.50 25.00 0.88350 0.80475 40.7550 36.15715 13.15789 8 CB19-PRD-S1 40 98.25 20.00 25.50 0.94575 0.82900 41.4675 38.70473 21.05263 9 CB19-PRD-S1 55 102.00 19.75 28.50 1.08125 0.95800 42.2775 44.25005 28.94737 10 CB19-PRD-S1 70 107.50 20.50 34.25 1.24400 1.14275 42.6450 50.91058 36.84211 11 CB19-PRD-S1 85 111.00 21.25 35.50 1.30475 1.19925 43.3600 53.39677 44.73684 12 CB19-PRD-S1 100 117.25 21.50 40.25 1.47350 1.42225 44.2650 60.30284 52.63158 13 CB19-PRD-S1 115 123.00 22.75 47.00 1.67900 1.68475 44.6400 68.71291 60.52632 14 CB19-PRD-S1 130 129.50 24.50 52.50 1.79075 1.87950 44.3425 73.28627 68.42105 15 CB19-PRD-S1 145 135.50 25.25 59.50 1.96000 2.13525 44.7300 80.21281 76.31579 16 CB19-PRD-S1 160 145.25 26.75 64.50 2.04050 2.28350 43.8825 83.50726 84.21053 17 CB19-PRD-S1 175 151.25 30.50 83.00 2.34425 2.76050 41.6025 95.93820 92.10526 18 CB19-PRD-S1 190 161.75 33.75 92.25 2.44350 2.96850 40.0400 100.00000 100.00000 19 CC14-PRD-S1 20 102.50 19.00 18.25 0.59250 0.54825 37.7175 49.26211 22.22222 20 CC14-PRD-S1 30 110.25 18.75 19.75 0.66100 0.60325 38.5800 54.95739 33.33333 21 CC14-PRD-S1 40 113.25 18.50 20.75 0.74350 0.66025 39.2950 61.81667 44.44444 22 CC14-PRD-S1 50 122.50 20.00 23.50 0.87875 0.77325 40.5650 73.06173 55.55556 23 CC14-PRD-S1 60 126.25 17.50 26.25 0.94350 0.89375 41.3525 78.44523 66.66667 24 CC14-PRD-S1 70 132.00 16.50 28.00 0.99675 0.98525 42.7575 82.87258 77.77778 25 CC14-PRD-S1 80 145.00 18.50 32.75 1.11425 1.16275 42.5025 92.64186 88.88889 26 CC14-PRD-S1 90 153.50 19.50 37.25 1.20275 1.32700 42.0975 100.00000 100.00000 27 DA24-PRD-S1 25 88.00 18.50 15.75 0.53500 0.45075 37.2200 40.33170 21.73913 28 DA24-PRD-S1 40 93.25 18.50 16.25 0.58450 0.47775 38.3375 44.06332 34.78261 29 DA24-PRD-S1 55 103.75 19.00 20.25 0.76875 0.65450 40.1875 57.95326 47.82609 30 DA24-PRD-S1 70 119.00 20.75 28.00 0.98200 0.95525 41.5175 74.02940 60.86957 31 DA24-PRD-S1 85 133.25 22.75 34.75 1.09975 1.18325 41.4125 82.90614 73.91304 32 DA24-PRD-S1 100 145.00 27.50 45.75 1.25900 1.49700 39.1475 94.91142 86.95652 33 DA24-PRD-S1 115 155.25 36.50 64.75 1.32650 1.72500 33.0275 100.00000 100.00000 I am running a plot using ggplot and ggscatter: ggplot(dftest, aes(percent_power, PETCO2)) + geom_point() ggscatter(dftest, x = "percent_power", y = "PETCO2", add = "reg.line") + stat_cor(label.x = 20, label.y = 3.8) + stat_regline_equation(label.x = 20, label.y = 0.5) + xlab("Percentage of power (%)") + geom_smooth(method = "lm", colour = "red") + ylab(expression(paste("PETC", O[2]," (mmHg)"))) I would like to perform a polynomial equation and curve because I am just able to run a linear regression. Thank you!
I think what you're asking is how to how to fit a polynomial regression line to your data while still using the ggpubr functions to annotate it. This is possible, but it seems that the in-built regression line can only be either a straight line or a loess model, neither of which is appropriate. However, you can fit a polynomial curve and get the equation and adjusted R-squared on the plot using the method below. In your case I have used a cubic formula, but you should choose your polynomial based on a known model or whatever makes most sense based on what you already know about the relationship between your variables. You can use ggplot to add the actual line as suggested by #Roland, as long as this uses the same formula as the one you supply to stat_regline_equation ggscatter(dftest, x = "percent_power", y = "PETCO2") + stat_regline_equation(label.x = 20, label.y = 0.5, formula = y ~ poly(x, 3), aes(label = paste(..eq.label.., ..adj.rr.label.., sep = "~~~~")),) + geom_smooth(method = "lm", formula = y ~ poly(x, 3)) + xlab("Percentage of power (%)") + ylab(expression(paste("PETC", O[2]," (mmHg)"))) Which gives this result:
Chrome: SVG container not rescaling responsively
I have an SVG that is effectively being used as a 'mask'; it's displayed over the top of another div with a background image so that the image peeks through the unfilled areas of the SVG. The SVG itself is responsive to the height of the document (rather than the width). This works fine so far. However, I've just been made aware that if you resize the (Chrome) browser, the background image overflows out of the bounds of the masking SVG; however, if you refresh the resized page, everything appears as expected - it only occurs on resize, and only in Chrome (oh, and Opera too, apparently). Works as expected in FF and Safari. I've included a demo here (and a jsFiddle) with an inline SVG, however it doesn't seem to matter if it's inline or with an <img /> tag - the results are the same. It seems to be somehow related to the containing element; if I open up the inspector and set the containing element's padding to 0 after it goes screwy, then it seems to figure itself out and suddenly appear as expected; however if I include that rule in the loaded CSS then it makes no difference. I even tried triggering similar CSS properties on page resize via Javascript, but it hasn't made any difference. Am I missing something, or have I stumbled across a bug? #splash { position: relative; height: 100vh; padding: 3rem; overflow: hidden; display: flex; -webkit-box-align: center; align-items: center; background-color: #DDDDDD; } #logowrapper { position: relative; width: auto; height: 60%; margin: auto; } #logowrapper .kitten { position: absolute; top: 0; left: 0; bottom: 0; right: 0; background-image: url('http://placekitten.com/200/300'); background-size: cover; } #logowrapper svg { position: relative; width: auto; height: 100%; z-index: 4; } <div id="splash"> <div id="logowrapper"> <div class="kitten"></div> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 200 300" preserveAspectRatio="xMinYMin meet"> <defs/> <g> <path stroke="none" fill="#DDDDDD" d="M110.95 215.1 Q100 225.6 100 240.7 100 256.25 110.75 266.85 121.45 277.5 137 277.5 153.9 277.5 165.45 267.4 177 257.35 177 242.5 177 226.85 166.7 216.1 155.6 204.6 137.5 204.6 121.85 204.6 110.95 215.1 M82.9 206.15 L82.2 206.05 80.3 206.05 Q75.15 206.05 71.55 207.25 66.35 208.95 66.35 212.7 66.35 215.65 67.75 216.9 L69.25 218.45 Q69.25 220.6 67.05 223.4 64.85 226.1 64.05 226.1 L63.8 226.1 Q62.45 225.9 60.35 223.3 58.25 220.75 58.25 218.4 58.25 217.8 59.6 217.1 60.95 216.3 60.95 214.7 L60.85 213.3 Q60.35 210.15 57.05 208.5 53.7 206.9 50.15 206.9 L32.8 206.9 27.25 207.75 Q21.85 209.3 21.85 213.1 21.85 214.8 23.35 216.2 24.85 217.8 28.4 219.3 29.9 219.9 35.1 226.2 40.3 232.5 44.5 239.15 45.2 240.05 45.4 242.35 L45.6 248.15 45.4 255.5 45 261.5 Q45 263.1 42.8 264.65 38.2 267.8 38.2 269.6 38.2 274.8 45.2 275.9 L58.55 276.5 61.45 276.5 64.35 276.6 Q69.45 276.6 72.2 275.6 75.85 274.1 77.25 270.45 L77.45 269.1 Q77.45 267.2 75.15 265.6 70.45 262.25 70.45 259.55 L70.45 238.95 86.05 218.7 Q86.3 218.45 91.45 216.9 95.1 215.75 95.1 212.05 95.1 208.35 93.45 207.15 91.6 205.95 88.5 205.95 L85.65 206.05 82.9 206.15 M127.75 222.3 Q130.15 219.2 133.85 219.2 141.8 219.2 146.9 232 151 242.15 151 251.7 151 256.7 148.6 259.6 146.2 262.4 142.2 262.4 135.1 262.4 129.75 249.5 125.35 238.95 125.35 230.4 125.35 225.5 127.75 222.3 M127 174.1 Q127.35 173.5 128.35 173.5 132.6 173.5 132.6 178.95 132.6 183.25 129 183.25 127.35 183.25 126.95 181.7 126.7 180.85 126.7 178.2 L126.65 176.9 126.6 175.7 Q126.6 174.7 127 174.1 M126.85 160.15 Q127.2 159.3 128.05 159.3 131.5 159.3 131.5 164.2 131.5 168.75 127.95 168.75 127.1 168.75 126.8 167.9 126.45 167.1 126.45 165.75 L126.5 164.8 126.6 163.8 126.55 163.5 126.5 162.2 Q126.5 161 126.85 160.15 M111.95 158.35 Q112.35 159 113.1 159 114.4 159 115.05 161.55 115.65 164.15 115.65 168.15 115.65 173.9 114.65 179 113.65 184.1 112.3 184.1 111.75 184.1 111.55 184.55 L111.35 185.8 Q111.35 186.95 112.3 187.65 113.2 188.35 114.7 188.35 L119.6 188.2 124.9 188.05 129.2 188.2 133.15 188.35 Q139 188.35 142.5 185.45 145.95 182.6 145.95 177.7 145.95 173.8 142.8 171.8 139.6 169.85 139.6 169.4 L142 166.2 Q143.1 164.4 143.1 162.15 143.1 157.75 139.35 155.9 136.65 154.55 131.8 154.55 L127.55 154.65 121.75 154.75 118.8 154.65 114.9 154.55 Q113.4 154.55 112.45 155.25 111.5 155.95 111.5 157 111.5 157.75 111.95 158.35 M106.65 123.3 L103.7 123.4 97.65 123.4 95.55 123.65 Q95.05 123.9 95.05 124.6 95.05 125.15 95.75 125.45 96.4 125.7 96.6 126 97.15 127.2 97.15 131.75 L97.05 134.45 96.8 136.4 Q96.6 137.2 95.9 137.6 95.2 137.95 95.2 138.45 95.2 139.45 96.45 139.45 L106.35 139.45 108.1 139.65 109.05 139.7 Q109.8 139.7 110.55 137.9 L111.2 135.45 110.9 134.3 Q110.55 133.9 110.05 133.9 109.7 133.9 108.65 135.5 107.5 137.1 104.5 137.1 102.9 137.1 102.55 136.65 102.25 136.15 102.25 133.95 102.25 133 102.4 132.65 102.6 132.35 103.15 132.35 104.35 132.35 104.65 133.55 104.9 134.75 105.45 134.75 106.15 134.75 106.6 133.75 107 132.7 107 131.05 107 129.4 106.65 128.5 106.25 127.6 105.6 127.6 104.8 127.6 104.6 128.85 104.35 130.1 103.5 130.1 L102.3 129.95 Q102.05 129.8 102.05 129.05 L102.05 127.05 Q102.05 126.2 102.45 125.9 L104 125.65 Q107.05 125.65 108 127.2 L109 127.85 Q110.25 127.85 110.25 126.2 110.25 124.95 109.65 123.95 109.1 122.95 108.4 122.95 L106.65 123.3 M150.65 132.95 L149.4 132.85 148.85 132.5 Q148.85 132.05 149.45 130.75 150 129.5 150.4 129.5 L151.55 130.75 Q152.3 132.05 152.3 132.55 L151.85 132.85 150.65 132.95 M158.5 133.55 Q156.15 128.3 155.2 126.7 153 123.05 150.85 123.05 148.25 123.05 148.25 126 L147.2 129.6 Q146.05 132.8 144.95 134.8 143.55 137.4 142.8 137.4 142.3 137.4 142.1 137.7 141.95 137.95 141.95 138.35 141.95 139.1 142.75 139.4 L145.5 139.7 Q148.9 139.7 148.9 138.3 148.9 137.75 148.2 137.5 147.45 137.2 147.45 136.9 147.45 136.1 147.85 135.9 L149.95 135.65 150.55 135.65 152.8 135.85 Q153.55 136.05 153.55 136.75 L153.1 137.3 Q152.15 137.75 152.15 138.35 152.15 139.25 153.5 139.45 L157.4 139.7 160.8 139.3 Q161.8 138.95 161.8 138.05 161.8 137.25 160.95 137.25 160.2 137.25 158.5 133.55 M125.05 123.2 L122.1 123.6 Q121.05 124.05 121.05 124.8 121.05 125.6 121.55 125.8 122.3 126.15 122.65 127.1 L126.95 138.15 Q127.3 139.05 127.75 139.4 128.15 139.75 128.9 139.75 130.15 139.75 131.15 137.75 L132.5 134.15 Q133.15 132.2 133.65 132.2 134.25 132.2 134.95 134.15 L136.25 137.75 Q137.2 139.7 138.45 139.7 139.2 139.7 139.65 139.15 L140.85 136.8 144.35 127.65 Q144.95 126.15 145.5 125.6 146.2 125 146.2 124.6 146.2 123.15 143.5 123.15 141.8 123.15 141 123.5 140.25 123.8 140.25 124.5 140.25 125.25 141 125.55 141.75 125.85 141.75 126.25 L141.05 128.7 Q140.35 130.45 139.95 130.45 139.6 130.45 138.7 128.75 137.8 127.05 137.8 126.15 L138.1 125.55 138.8 124.55 Q138.8 123.85 137.8 123.5 L134.45 123.2 Q130 123.2 130 124.65 130 125.2 130.95 126.05 131.95 126.9 131.95 127.6 L131.6 129.15 Q131.15 130.7 130.5 130.7 130.1 130.7 129.3 128.55 128.55 126.6 128.55 126.15 L128.75 125.6 129.1 124.65 Q129.1 123.8 128.25 123.5 L125.05 123.2 M58.85 159.05 Q53.65 164.05 53.65 171.25 53.65 178.65 58.75 183.7 63.85 188.75 71.25 188.75 79.3 188.75 84.8 183.95 90.3 179.15 90.3 172.1 90.3 164.65 85.4 159.55 80.1 154.05 71.5 154.05 64.05 154.05 58.85 159.05 M69.75 161 Q73.55 161 76 167.1 77.95 171.95 77.95 176.5 77.95 178.85 76.8 180.25 75.65 181.6 73.75 181.6 70.35 181.6 67.8 175.45 65.7 170.4 65.7 166.35 65.7 164 66.85 162.5 68 161 69.75 161 M25.65 154.5 L24.4 154.2 Q21.85 154.2 19.85 157.7 18.1 160.75 18.1 163.25 18.1 164.7 18.8 165.85 19.45 167 20.65 167 22.7 167 24.8 164.3 26.9 161.6 27.55 161.6 28.6 161.6 29 162.95 29.4 164.35 29.4 166.75 L29.3 169.4 29.2 172.6 29 176.6 28.3 180.95 Q28.1 181.7 26.3 182.65 24.5 183.6 24.5 184.55 24.5 186.9 28.1 187.75 L34.9 188.3 Q40.5 188.3 42.7 187.3 44.95 186.35 44.95 184.7 44.95 183.35 43.15 182.65 41.4 182 41.2 181.25 40.55 178.55 40.4 177.05 L40.2 173 Q40.2 169 40.5 165.25 40.8 161.5 41.4 161.5 43.35 161.5 44.6 164.15 45.85 166.8 48.4 166.8 49.9 166.8 50.95 165.65 52 164.5 52 162.9 52 160.4 50.6 157.45 48.95 154.05 46.6 154.05 L46.3 154.05 45.35 154.35 44.15 154.7 26.95 154.8 25.65 154.5 M29.4 123.45 L28.55 123.45 Q26.1 123.45 25.05 123.95 24.2 124.35 24.2 125.1 24.2 125.45 24.65 125.8 25.65 126.55 25.75 127.3 L25.85 129.35 25.85 129.75 25.85 130.15 25.75 132.8 25.7 135.35 Q25.7 136.4 24.5 137.05 23.95 137.35 23.95 137.75 23.95 138.9 25.25 139.25 L27.9 139.5 28.65 139.5 31.45 139.3 Q32.9 139 32.9 138.2 32.9 137.65 32.2 136.95 L31.4 135.8 31.35 134.15 31.25 132.35 31.4 129.05 31.5 127.1 Q31.5 126.8 32.45 125.9 32.9 125.5 32.9 124.95 32.9 123.95 31.8 123.65 L29.4 123.45 M43.05 123.3 L41.3 123.1 Q38.5 123.1 36.6 124.65 34.7 126.25 34.7 128.6 34.7 130.8 36.75 132.3 37.7 133 40.5 134.2 42.55 135.1 42.55 135.75 42.55 136.25 42 136.55 L40.6 136.85 Q38.35 136.85 37.05 135.05 35.7 133.25 35.25 133.25 34.25 133.25 34.25 134.55 34.25 137.15 35.6 138.3 37.2 139.75 41.45 139.75 44.7 139.75 46.75 138.2 48.8 136.6 48.8 134.05 48.8 131.65 46.75 130.35 45.95 129.85 42.95 128.8 40.9 128.1 40.9 127.2 40.9 126.65 41.3 126.35 41.7 126.05 42.35 126.05 43.55 126.05 45.05 127.35 46.55 128.7 47.2 128.7 47.75 128.7 48.15 128.2 48.55 127.75 48.55 127.1 48.55 126.1 47.75 124.85 46.95 123.45 46 123.45 L45.4 123.6 44.9 123.75 43.05 123.3 M80 123.35 L77.15 123.6 Q75.65 123.95 75.65 125 75.65 125.55 76.15 125.75 L77.1 126.45 77.35 127.6 77.4 130.25 77.25 134.5 76.8 136.8 76 137.15 Q75.5 137.3 75.5 137.9 75.5 138.95 76.95 139.35 L79.6 139.6 82.45 139.3 Q84.05 138.9 84.05 138.05 L84.05 137.95 Q84.05 137.5 83.6 137.15 82.5 136.35 82.5 134.5 82.5 133.45 82.8 133.05 83.25 132.5 84.7 132.5 L86.4 132.7 Q86.75 132.9 86.75 133.45 L86.7 133.9 86.7 134.35 Q86.7 136.55 85.65 137.2 85.2 137.5 85.2 138.2 85.2 138.95 86.6 139.4 L89.1 139.7 91.4 139.6 Q93.75 139.3 93.75 138.05 93.75 137.5 93.25 137.3 92.25 136.85 92.25 132.5 92.25 126.5 93.45 125.75 94 125.4 94 124.85 94 124 92.65 123.6 L90.15 123.25 87.8 123.4 Q85.3 123.75 85.3 124.9 85.3 125.3 86.05 125.9 86.8 126.5 86.8 128.1 L86.65 129.45 Q86.5 129.75 85.8 129.75 L85.35 129.7 84.9 129.7 84.4 129.75 83.95 129.75 Q83.2 129.75 82.95 129.45 82.6 129.1 82.6 128.05 82.6 126.45 83.8 125.75 84.2 125.45 84.2 124.95 L84.2 124.85 Q84.1 123.85 82.65 123.5 L80 123.35 M62.25 123.35 L61.65 123.15 Q60.45 123.15 59.5 124.85 58.65 126.3 58.65 127.5 58.65 128.2 59 128.75 59.3 129.35 59.85 129.35 60.85 129.35 61.85 128 62.85 126.75 63.2 126.75 63.7 126.75 63.9 127.4 L64.05 129.2 64 130.45 64 132 63.9 133.95 63.55 136 62.6 136.85 Q61.75 137.3 61.75 137.75 61.75 138.9 63.45 139.3 L66.7 139.55 70.45 139.05 Q71.5 138.6 71.5 137.8 71.5 137.2 70.7 136.85 69.85 136.5 69.75 136.15 L69.35 134.15 69.25 132.2 Q69.25 130.3 69.4 128.5 69.55 126.7 69.85 126.7 70.75 126.7 71.35 127.95 71.95 129.25 73.2 129.25 73.9 129.25 74.4 128.65 74.9 128.1 74.9 127.35 74.9 126.15 74.25 124.75 73.45 123.1 72.35 123.1 L72.2 123.1 71.75 123.25 71.15 123.4 62.9 123.45 62.25 123.35 M24.6 90.45 Q21.7 90.45 21.7 94.35 21.7 102.15 25.7 105.65 30.55 110.05 43.2 110.05 53 110.05 59.2 105.3 65.35 100.55 65.35 92.95 65.35 85.7 59.2 81.75 56.8 80.25 47.7 77.15 41.55 75.05 41.55 72.35 41.55 70.65 42.8 69.75 44 68.85 46 68.85 49.6 68.85 54.05 72.8 58.5 76.8 60.5 76.8 62.2 76.8 63.35 75.4 64.5 74.05 64.5 72.05 64.5 69 62.2 65.25 59.7 61.15 56.95 61.15 56.25 61.15 55.15 61.6 L53.55 62.05 48 60.6 42.8 60 Q34.4 60 28.7 64.75 23 69.5 23 76.5 23 83.15 29.1 87.7 32 89.75 40.45 93.4 46.5 96 46.5 98 46.5 99.45 44.9 100.35 43.25 101.3 40.75 101.3 33.95 101.3 30 95.85 26.05 90.45 24.6 90.45 M24.1 34.7 Q24.1 33.75 24.95 33.75 26.55 33.75 26.55 36.05 26.55 38.25 24.6 38.25 24.2 38.25 24.1 38.1 23.95 37.9 23.95 37.5 L24.1 34.7 M19.6 31.3 Q16.95 31.3 16.95 32.7 16.95 33.2 17.5 33.45 18.7 33.95 18.7 37 L18.65 41.9 Q18.65 44.55 17.5 45.25 16.95 45.6 16.95 46.05 16.95 47.7 21.3 47.7 L24.6 47.35 Q25.6 47.05 25.6 46.25 25.6 45.7 25.1 45.4 24.1 44.8 24.1 42.25 L24.1 41.95 24.2 41.15 Q24.3 40.75 24.8 40.75 26.05 40.75 26.6 42.6 27.5 45.7 27.75 46.05 28.85 47.9 31.5 47.9 L34.15 47.45 Q35.15 46.95 35.15 46.15 35.15 45.6 34.35 45.3 33.5 45 33.4 43.9 33.1 41.6 32.1 40.55 31.2 39.55 30.2 39.2 L31.75 37.75 Q32.5 36.85 32.5 35.45 32.5 33.55 30.95 32.4 29.4 31.2 26.85 31.2 L24.05 31.4 22.35 31.45 21 31.35 19.6 31.3 M76.35 33.8 Q77.4 33.8 78 34.5 78.6 35.2 78.6 36.45 78.6 37.7 78.05 38.35 77.5 39 76.5 39 L75.7 38.8 75.45 38.25 75.45 34.25 Q75.45 33.8 76.35 33.8 M42.9 33.9 L44.45 33.65 Q47.5 33.65 48.45 35.2 48.85 35.85 49.45 35.85 50.7 35.85 50.7 34.2 50.7 32.95 50.1 31.95 49.55 30.95 48.85 30.95 L47.1 31.3 44.15 31.4 38.1 31.4 36 31.65 Q35.5 31.9 35.5 32.6 35.5 33.15 36.2 33.45 L37.05 34 Q37.6 35.2 37.6 39.75 L37.5 42.45 37.25 44.4 Q37.05 45.2 36.35 45.6 35.65 45.95 35.65 46.45 35.65 47.45 36.9 47.45 L46.8 47.45 48.55 47.65 49.5 47.7 Q50.25 47.7 51 45.9 L51.65 43.45 51.35 42.3 Q51 41.9 50.5 41.9 50.15 41.9 49.1 43.5 47.95 45.1 44.95 45.1 43.35 45.1 43 44.65 42.7 44.15 42.7 41.95 42.7 41 42.85 40.65 43.05 40.35 43.6 40.35 44.8 40.35 45.1 41.55 45.35 42.75 45.9 42.75 46.6 42.75 47.05 41.75 47.45 40.7 47.45 39.05 47.45 37.4 47.1 36.5 46.7 35.6 46.05 35.6 45.25 35.6 45.05 36.85 44.8 38.1 43.95 38.1 L42.75 37.95 Q42.5 37.8 42.5 37.05 L42.5 35.05 Q42.5 34.2 42.9 33.9 M55.05 32.65 Q53.15 34.25 53.15 36.6 53.15 38.8 55.2 40.3 56.15 41 58.95 42.2 61 43.1 61 43.75 61 44.25 60.45 44.55 L59.05 44.85 Q56.8 44.85 55.5 43.05 54.15 41.25 53.7 41.25 52.7 41.25 52.7 42.55 52.7 45.15 54.05 46.3 55.65 47.75 59.9 47.75 63.15 47.75 65.2 46.2 67.25 44.6 67.25 42.05 67.25 39.65 65.2 38.35 64.4 37.85 61.4 36.8 59.35 36.1 59.35 35.2 59.35 34.65 59.75 34.35 60.15 34.05 60.8 34.05 62 34.05 63.5 35.35 65 36.7 65.65 36.7 66.2 36.7 66.6 36.2 67 35.75 67 35.1 67 34.1 66.2 32.85 65.4 31.45 64.45 31.45 L63.85 31.6 63.35 31.75 61.5 31.3 59.75 31.1 Q56.95 31.1 55.05 32.65 M117.5 61.3 L111.75 61 Q107 61 104.5 61.75 100.8 62.8 100.8 65.6 100.8 66.9 102.85 68.15 104.25 68.9 104.25 69.75 L104.1 70.2 98.1 84.15 97.2 84.4 Q96.25 84.4 96.05 83.9 L90.55 70.55 90.5 70.2 Q90.5 69.45 91.95 68.65 93.6 67.7 93.6 65.9 93.6 62.45 89.2 61.65 L80.95 61 79.7 60.85 78.4 60.85 Q73.8 60.85 70.4 62.3 66.95 63.75 66.95 66.5 66.95 68.15 69.35 69.1 71.6 70.1 72.05 70.95 L76.25 80.65 83.75 98.3 Q87.8 107.75 88.35 107.75 88.85 108.9 90.2 109.55 91.5 110.25 92.95 110.25 96.4 110.25 97.5 107.85 98.4 107.85 104.85 94 110.9 80.85 115.05 70.55 115.75 68.9 118.05 68.35 120.4 67.8 120.4 65.45 120.4 61.95 117.5 61.3 M115.25 32.9 Q115.25 33.5 115.95 33.9 116.65 34.3 116.75 34.65 L116.9 35.5 116.95 36.45 Q116.95 37.9 116.25 37.9 115.9 37.9 115 37.2 114.45 36.75 112.85 35.3 L110.1 32.7 Q109.3 31.95 108.75 31.75 L107.5 31.5 107.2 31.5 106.55 31.5 104.15 31.8 Q102.9 32.2 102.9 33.1 102.9 33.5 103.5 33.85 L104.4 34.5 104.95 36.85 105.15 39.3 105 42 104.6 44.7 103.75 45.45 103.35 46.15 Q103.35 46.9 104.45 47.3 L106.6 47.65 Q108.3 47.65 109.2 47.15 109.9 46.8 110.05 46.05 110.05 45.65 109.65 45.3 L108.85 44.7 108.45 43.4 108.25 41.8 108.45 40.55 Q108.6 40.1 108.9 40.1 109.6 40.1 111.8 42.05 L115.65 45.7 Q117.8 47.65 118.5 47.65 119.25 47.65 119.6 46.5 119.9 45.4 119.9 41.25 L120 37.35 Q120.1 35.8 120.35 34.7 120.45 34.35 120.95 34.1 121.95 33.55 121.95 32.8 121.95 32 120.95 31.65 L119.3 31.45 118.9 31.45 118.75 31.45 118.7 31.45 118.4 31.45 116.45 31.7 Q115.25 32.05 115.25 32.9 M90.55 37 Q90.55 35.9 91.1 35.15 91.65 34.45 92.5 34.45 94.3 34.45 95.45 37.35 96.4 39.7 96.4 41.85 96.4 43 95.85 43.7 95.3 44.3 94.4 44.3 92.75 44.3 91.55 41.35 90.55 38.95 90.55 37 M83.9 36.35 Q83.9 34.1 82.2 32.65 80.5 31.25 77.75 31.25 L73.65 31.5 71.2 31.6 70.55 31.55 69.95 31.55 68.55 31.8 Q68.05 32 68.05 32.65 68.05 33.4 68.75 33.6 70.2 34 70.2 35.75 L70.2 43.2 Q70.2 44.95 69.05 45.5 68.5 45.75 68.5 46.2 68.5 47.7 72.7 47.7 77.15 47.7 77.15 46.15 77.15 45.8 76.35 45.25 75.45 44.65 75.45 43.85 L75.4 41.85 Q75.4 41.45 76.15 41.45 L76.85 41.5 77.8 41.6 Q80.5 41.6 82.2 40.15 83.9 38.65 83.9 36.35 M100 33.75 Q97.45 31.1 93.3 31.1 89.75 31.1 87.25 33.5 84.75 35.9 84.75 39.35 84.75 42.9 87.2 45.35 89.65 47.75 93.2 47.75 97.05 47.75 99.7 45.45 102.35 43.15 102.35 39.75 102.35 36.2 100 33.75 M139.25 33.8 Q140.25 34.55 140.35 35.3 L140.45 37.35 140.45 37.75 140.45 38.15 140.35 40.8 140.3 43.35 Q140.3 44.4 139.1 45.05 138.55 45.35 138.55 45.75 138.55 46.9 139.85 47.25 L142.5 47.5 143.25 47.5 146.05 47.3 Q147.5 47 147.5 46.2 147.5 45.65 146.8 44.95 146.1 44.3 146 43.8 L145.95 42.15 145.85 40.35 146 37.05 146.1 35.1 Q146.1 34.8 147.05 33.9 L147.5 32.95 Q147.5 31.95 146.4 31.65 L144 31.45 143.15 31.45 Q140.7 31.45 139.65 31.95 138.8 32.35 138.8 33.1 138.8 33.45 139.25 33.8 M136.45 32.85 Q135.65 31.45 134.7 31.45 L134.1 31.6 133.6 31.75 131.75 31.3 130 31.1 Q127.2 31.1 125.3 32.65 123.4 34.25 123.4 36.6 123.4 38.8 125.45 40.3 126.4 41 129.2 42.2 131.25 43.1 131.25 43.75 131.25 44.25 130.7 44.55 L129.3 44.85 Q127.05 44.85 125.75 43.05 124.4 41.25 123.95 41.25 122.95 41.25 122.95 42.55 122.95 45.15 124.3 46.3 125.9 47.75 130.15 47.75 133.4 47.75 135.45 46.2 137.5 44.6 137.5 42.05 137.5 39.65 135.45 38.35 134.65 37.85 131.65 36.8 129.6 36.1 129.6 35.2 129.6 34.65 130 34.35 130.4 34.05 131.05 34.05 132.25 34.05 133.75 35.35 135.25 36.7 135.9 36.7 136.45 36.7 136.85 36.2 137.25 35.75 137.25 35.1 137.25 34.1 136.45 32.85 M177.65 155.8 Q176.45 153.75 175 153.75 L171.4 154.4 165.2 154.7 152.6 154.7 148.3 155.15 Q147.25 155.65 147.25 157.15 147.25 158.35 148.65 158.9 150.05 159.45 150.4 160.1 151.6 162.6 151.6 172.1 L151.4 177.7 150.85 181.7 Q150.45 183.45 149 184.2 147.5 184.95 147.5 186 147.5 188.1 150.1 188.1 L170.8 188.1 174.4 188.45 176.35 188.6 Q178 188.6 179.55 184.85 180.85 181.7 180.85 179.75 180.85 178.3 180.2 177.4 179.55 176.5 178.5 176.5 177.75 176.5 175.5 179.85 173.2 183.25 166.9 183.25 163.55 183.25 162.85 182.25 162.2 181.25 162.2 176.6 162.2 174.65 162.55 173.95 162.95 173.3 164.05 173.3 166.65 173.3 167.2 175.8 167.75 178.3 168.9 178.3 170.35 178.3 171.25 176.2 172.15 174.1 172.15 170.65 172.15 167.2 171.35 165.3 170.55 163.4 169.15 163.4 167.55 163.4 167.1 166 166.65 168.65 164.85 168.65 L162.3 168.3 Q161.8 168 161.8 166.45 L161.85 162.3 Q161.85 160.5 162.65 159.9 163.4 159.35 165.85 159.35 172.2 159.35 174.15 162.55 175 163.95 176.25 163.95 178.85 163.95 178.85 160.5 178.85 157.9 177.65 155.8 M173.1 123.45 L172.65 123.45 170.65 123.7 Q169.45 124.1 169.45 124.95 169.45 125.65 169.8 125.9 L170.15 126.3 169.65 127.4 168.95 128 168.9 128 Q168.55 128 168.1 127.4 167.6 126.8 167.6 126.25 L167.95 125.95 168.25 125.4 168.2 125.1 Q168.1 124.4 167.35 124 166.6 123.65 165.75 123.65 L161.8 123.65 160.55 123.85 Q159.3 124.2 159.3 125.05 159.3 125.45 159.65 125.75 160 126.15 160.8 126.45 L162.35 128.05 164.45 131 164.7 131.75 164.75 133.05 164.7 134.75 164.6 136.1 164.1 136.85 Q163.05 137.55 163.05 137.95 163.05 139.15 164.65 139.4 L167.7 139.55 168.35 139.55 169 139.55 170.8 139.35 Q171.65 139 171.95 138.15 L172 137.85 Q172 137.4 171.5 137.05 170.4 136.3 170.4 135.65 L170.4 130.95 174 126.35 175.2 125.9 Q176.05 125.65 176.05 124.8 176.05 123.95 175.65 123.7 175.25 123.4 174.55 123.4 L173.9 123.45 173.25 123.45 173.1 123.45 M165.9 61 L164.2 61.35 161.45 62.1 154.65 60.35 Q151.4 59.55 149.2 59.55 139 59.55 130.85 67.65 122.7 75.7 122.7 85.05 122.7 96.6 130.45 103.5 138.15 110.4 150.5 110.4 164.5 110.4 170.3 101 L173.55 94.1 177.15 92.7 Q178.6 91.85 178.6 90.2 178.6 87 173.95 85.5 170.4 84.35 164.8 84.35 158.15 84.35 154.7 85.35 149.8 86.8 149.8 90.5 149.8 93.3 153.6 93.75 157.45 94.2 157.45 96.25 157.45 98.05 156.35 99.3 155.2 100.6 153.25 100.6 148.8 100.6 144.9 94.55 141.05 88.55 141.05 82.45 141.05 77.3 143.15 73.7 145.8 69.35 150.8 69.35 154.85 69.35 159.1 74.05 163.35 78.75 166.95 78.75 169.15 78.75 170.65 77 172.1 75.3 172.1 72.95 172.1 69.65 170.55 65.75 168.6 61 165.9 61 M165.3 31.5 L163.4 31.4 160.95 31.65 Q159.75 32 159.75 32.95 159.75 33.4 160.4 33.8 L160.9 34.35 160.85 34.5 158.85 39.15 158.55 39.2 158.15 39.05 156.3 34.6 156.3 34.5 Q156.3 34.25 156.8 33.95 157.35 33.65 157.35 33.05 157.35 31.9 155.85 31.65 L153.1 31.4 152.7 31.35 152.25 31.35 Q150.75 31.35 149.6 31.85 148.45 32.35 148.45 33.25 148.45 33.8 149.25 34.1 150 34.45 150.15 34.75 L151.55 37.95 154.05 43.85 155.6 47 Q155.75 47.4 156.2 47.6 L157.1 47.85 Q158.25 47.85 158.65 47.05 158.95 47.05 161.1 42.4 L164.5 34.6 Q164.7 34.05 165.5 33.85 166.25 33.7 166.25 32.9 166.25 31.75 165.3 31.5 M174.1 33.9 L175.65 33.65 Q178.7 33.65 179.65 35.2 L180.65 35.85 Q181.9 35.85 181.9 34.2 181.9 32.95 181.3 31.95 180.75 30.95 180.05 30.95 L178.3 31.3 175.35 31.4 169.3 31.4 167.2 31.65 Q166.7 31.9 166.7 32.6 166.7 33.15 167.4 33.45 168.05 33.7 168.25 34 168.8 35.2 168.8 39.75 L168.7 42.45 168.45 44.4 Q168.25 45.2 167.55 45.6 166.85 45.95 166.85 46.45 166.85 47.45 168.1 47.45 L178 47.45 179.75 47.65 180.7 47.7 Q181.45 47.7 182.2 45.9 182.85 44.4 182.85 43.45 182.85 42.75 182.55 42.3 182.2 41.9 181.7 41.9 181.35 41.9 180.3 43.5 179.15 45.1 176.15 45.1 174.55 45.1 174.2 44.65 173.9 44.15 173.9 41.95 173.9 41 174.05 40.65 174.25 40.35 174.8 40.35 176 40.35 176.3 41.55 176.55 42.75 177.1 42.75 177.8 42.75 178.25 41.75 178.65 40.7 178.65 39.05 178.65 37.4 178.3 36.5 177.9 35.6 177.25 35.6 176.45 35.6 176.25 36.85 176 38.1 175.15 38.1 L173.95 37.95 Q173.7 37.8 173.7 37.05 L173.7 35.05 Q173.7 34.2 174.1 33.9 M200 0 L200 300 0 300 0 0 200 0"/> </g> </svg> </div> </div>
If you want to use a responsive inline SVG in your HTML, the SVG shouldn't have width and height attributes. Update: Maybe It's a bug on Blink (or Webkit). And I tried to use a redraw hack. https://jsfiddle.net/pbg1g4uv/2/ #logowrapper svg { position: relative; width: auto; height: 100%; z-index: 4; animation: redraw 1s infinite; } #keyframes redraw { from { min-width: 1px; } to { min-width: 2px; } }
PerformanceAnalytics + data.frame: Formatting issue when using package functions
I'm trying to pass a data.frame with dates in the rownames into a PerformanceAnalytics (package) function. My data is below, I get the following error message when trying to run the code > charts.PerformanceSummary(x$Return) Error in checkData(R) : The data cannot be converted into a time series. If you are trying to pass in names from a data object with one column, you should use the form 'data[rows, columns, drop = FALSE]'. Rownames should have standard date formats, such as '1985-03-15'. How can this be solved? I thought that PerformanceAnalytics would recognize my rows as dates automatically. My data > str(x) 'data.frame': 201 obs. of 7 variables: $ Open : num 69 67.8 64 67.2 68 ... $ High : num 70 69 67.8 68.8 70.8 ... $ Low : num 67 66 63.2 64.5 67.5 ... $ Close : num 68.5 66 67.2 68 68.5 ... $ Volume : num 2163200 2456100 2783000 2200300 2418000 ... $ Adj.Close: num 55 53 54 54.6 55 ... $ Return : num 0 0 0 0 0 0 0 0 0 0 ... > x Open High Low Close Volume Adj.Close Return 2008-11-28 69.00 70.00 67.00 68.50 2163200 54.9989 0.000000000 2008-12-01 67.75 69.00 66.00 66.00 2456100 52.9916 0.000000000 2008-12-02 64.00 67.75 63.25 67.25 2783000 53.9953 0.000000000 2008-12-03 67.25 68.75 64.50 68.00 2200300 54.5974 0.000000000 2008-12-04 68.00 70.75 67.50 68.50 2418000 54.9989 0.000000000 2008-12-05 68.00 68.75 63.50 64.50 2162200 51.7873 0.000000000 2008-12-08 67.25 73.50 67.25 72.00 4363100 57.8090 0.000000000 2008-12-09 71.25 76.25 70.00 74.50 4266500 59.8163 0.000000000 2008-12-10 73.75 78.00 73.00 77.50 3395900 62.2250 0.000000000 2008-12-11 76.75 76.75 74.25 76.00 2474600 61.0207 0.000000000 2008-12-12 74.00 74.75 72.25 74.50 3141800 59.8163 0.000000000 2008-12-15 70.00 74.50 67.25 67.25 7125600 53.9953 0.000000000 2008-12-16 66.25 69.50 66.00 69.50 3063200 55.8018 0.000000000 2008-12-17 69.25 70.00 67.00 70.00 2543400 56.2032 0.000000000 2008-12-18 69.50 73.50 69.25 72.25 4366000 58.0098 0.000000000 2008-12-19 70.50 72.00 69.75 71.75 2346600 57.6083 0.000000000 2008-12-22 70.50 71.00 68.25 69.75 3057600 56.0025 0.000000000 2008-12-23 68.75 69.50 67.50 69.25 2327700 55.6011 0.000000000 2008-12-24 69.25 69.25 69.25 69.25 0 55.6011 0.000000000 2008-12-25 69.25 69.25 69.25 69.25 0 55.6011 0.000000000 2008-12-26 69.25 69.25 69.25 69.25 0 55.6011 0.000000000 2008-12-29 69.00 69.75 67.50 68.00 1187600 54.5974 0.000000000 2008-12-30 67.75 68.50 66.50 66.75 1888700 53.5938 0.000000000 2008-12-31 66.75 66.75 66.75 66.75 0 53.5938 0.000000000 2009-01-01 66.75 66.75 66.75 66.75 0 53.5938 0.000000000 2009-01-02 67.75 72.75 67.00 72.25 1887500 58.0098 0.000000000 2009-01-05 73.75 75.50 73.00 74.25 2020400 59.6156 0.000000000 2009-01-06 74.25 74.25 74.25 74.25 0 59.6156 0.000000000 2009-01-07 73.75 75.00 73.50 74.50 2962600 59.8163 0.000000000 2009-01-08 73.00 74.25 71.00 72.25 2239100 58.0098 0.000000000 2009-01-09 72.00 72.25 70.25 71.25 1983600 57.2069 0.000000000 2009-01-12 69.50 71.00 69.00 69.75 1487000 56.0025 0.000000000 2009-01-13 68.75 69.75 67.75 68.75 2859100 55.1996 0.000000000 2009-01-14 69.75 69.75 63.25 64.25 2586900 51.5865 0.000000000 2009-01-15 64.00 66.50 60.75 63.00 4090800 50.5829 0.000000000 2009-01-16 65.00 66.00 64.00 64.75 2455600 51.9880 0.000000000 2009-01-19 66.00 66.00 64.75 65.50 2839200 52.5902 0.000000000 2009-01-20 66.00 66.75 62.25 62.75 2787600 50.3822 0.000000000 2009-01-21 62.00 67.50 61.75 65.25 5090700 52.3894 0.000000000 2009-01-22 67.00 69.00 65.50 65.75 2994600 52.7909 0.000000000 2009-01-23 64.75 66.00 61.25 62.00 4463400 49.7800 0.000000000 2009-01-26 62.00 65.75 61.50 65.75 3698700 52.7909 0.000000000 2009-01-27 66.00 67.25 64.75 65.75 3445900 52.7909 0.000000000 2009-01-28 66.25 69.00 66.00 67.00 2766400 53.7945 0.000000000 2009-01-29 67.00 67.25 62.25 62.75 2090700 50.3822 0.000000000 2009-01-30 63.00 63.75 59.00 60.50 6437600 48.5757 0.000000000 2009-02-02 60.25 62.00 58.75 60.25 3267600 48.3749 0.000000000 2009-02-03 60.75 62.50 59.25 62.50 3148000 50.1815 0.000000000 2009-02-04 62.75 69.50 61.75 68.25 6579500 54.7982 0.000000000 2009-02-05 66.00 69.50 66.00 69.00 6733600 55.4003 0.000000000 2009-02-06 69.00 71.00 68.25 70.00 5031600 56.2032 0.000000000 2009-02-09 69.50 72.00 68.75 71.75 3794200 57.6083 0.000000000 2009-02-10 70.25 72.00 69.75 70.75 2991500 56.8054 0.000000000 2009-02-11 68.75 70.75 68.25 68.50 2566400 54.9989 0.000000000 2009-02-12 67.75 70.25 66.75 70.00 3083800 56.2032 0.000000000 2009-02-13 70.25 71.50 68.00 69.25 2227000 55.6011 0.000000000 2009-02-16 68.50 69.25 67.25 68.75 1087100 55.1996 0.000000000 2009-02-17 67.50 67.50 65.00 65.50 1630200 52.5902 0.000000000 2009-02-18 65.00 65.50 62.50 65.00 40400 52.1887 0.000000000 2009-02-19 65.00 68.00 64.50 66.50 2701100 53.3931 0.000000000 2009-02-20 64.25 65.00 60.75 61.25 5534300 49.1778 0.000000000 2009-02-23 62.00 62.50 58.50 58.75 2524300 47.1706 0.000000000 2009-02-24 58.75 60.25 56.75 58.00 5117600 46.5684 0.000000000 2009-02-25 59.50 61.75 59.25 60.25 4418400 48.3749 0.000000000 2009-02-26 61.50 64.50 60.50 63.50 6482600 50.9844 0.000000000 2009-02-27 61.50 62.75 60.00 62.00 2834500 49.7800 0.000000000 2009-03-02 61.25 61.25 58.00 59.50 3087100 47.7727 0.000000000 2009-03-03 60.00 60.75 57.75 58.50 2606300 46.9698 0.000000000 2009-03-04 60.00 60.00 58.00 59.75 4554800 47.9735 0.000000000 2009-03-05 59.00 59.75 57.25 58.00 2777600 46.5684 0.000000000 2009-03-06 56.50 58.75 56.50 57.50 3338300 46.1669 0.000000000 2009-03-09 58.50 58.75 57.00 58.00 3708500 46.5684 0.000000000 2009-03-10 58.00 61.00 57.50 60.25 5163300 48.3749 0.000000000 2009-03-11 60.00 62.75 59.00 61.50 3668700 49.3786 0.000000000 2009-03-12 61.50 61.75 58.50 61.25 3404600 49.1778 0.000000000 2009-03-13 63.00 64.00 60.75 62.00 4048500 49.7800 0.000000000 2009-03-16 63.00 64.50 62.25 62.50 2945300 50.1815 0.000000000 2009-03-17 62.75 62.75 60.50 60.75 2369800 48.7764 0.000000000 2009-03-18 62.25 62.50 59.25 60.25 1968600 48.3749 0.000000000 2009-03-19 61.00 64.75 60.25 64.25 3730400 51.5865 0.000000000 2009-03-20 63.75 65.00 63.50 63.50 3186200 50.9844 0.000000000 2009-03-23 64.75 65.50 63.00 65.50 2738400 52.5902 0.000000000 2009-03-24 65.50 66.00 63.00 64.50 2994200 51.7873 0.000000000 2009-03-25 63.75 69.00 62.75 67.75 4342500 54.3967 0.000000000 2009-03-26 67.00 69.25 66.75 68.00 8300 54.5974 0.000000000 2009-03-27 67.75 69.50 66.75 68.50 3407200 54.9989 0.000000000 2009-03-30 66.75 67.00 63.75 64.50 3123200 51.7873 0.000000000 2009-03-31 64.00 66.25 63.00 64.50 3261600 51.7873 0.000000000 2009-04-01 64.50 64.75 60.75 64.25 6808900 51.5865 0.000000000 2009-04-02 67.00 73.25 66.75 72.75 8180500 58.4112 0.000000000 2009-04-03 72.00 76.50 71.25 75.75 5628500 60.8199 0.000000000 2009-04-06 76.00 76.75 74.25 75.00 3238900 60.2178 0.000000000 2009-04-07 75.75 76.00 72.25 73.75 3765800 59.2141 0.000000000 2009-04-08 72.00 75.75 71.50 75.50 3177100 60.6192 0.000000000 2009-04-09 75.50 76.00 74.25 76.00 887600 61.0207 0.000000000 2009-04-10 76.00 76.00 76.00 76.00 0 61.0207 0.000000000 2009-04-13 76.00 76.00 76.00 76.00 0 61.0207 0.000000000 2009-04-14 78.00 80.75 77.00 79.00 3923200 63.4294 0.000000000 2009-04-15 78.00 79.00 75.75 76.00 2425700 61.0207 0.000000000 2009-04-16 77.50 79.50 76.00 79.25 3331200 63.6301 0.000000000 2009-04-17 79.25 83.00 79.00 81.25 4058600 65.2359 0.000000000 2009-04-20 80.00 80.50 75.75 76.75 3682800 61.6228 0.000000000 2009-04-21 76.25 76.75 73.25 75.75 3293500 60.8199 0.000000000 2009-04-22 84.00 91.50 82.00 88.00 10525000 70.6555 0.000000000 2009-04-23 89.75 92.75 88.75 90.25 5664200 72.4620 0.000000000 2009-04-24 90.75 94.75 89.50 93.75 3982600 75.2722 0.000000000 2009-04-27 92.25 100.25 91.75 97.50 4702300 78.2831 0.000000000 2009-04-28 95.75 96.00 92.25 95.00 6479800 76.2758 0.000000000 2009-04-29 94.50 97.50 92.75 95.00 2565300 76.2758 0.000000000 2009-04-30 95.00 96.75 92.00 92.00 2480500 73.8671 0.000000000 2009-05-01 92.00 92.00 92.00 92.00 0 73.8671 0.000000000 2009-05-04 95.75 100.00 94.00 100.00 3653000 80.2903 0.086956169 2009-05-05 100.00 101.75 97.75 97.75 3400 78.4838 -0.022499605 2009-05-06 98.00 104.00 96.50 102.75 4010500 82.4983 0.051150683 2009-05-07 104.25 105.00 98.50 99.75 5145800 80.0896 -0.029196965 2009-05-08 101.25 103.25 99.25 100.25 2782200 80.4911 0.005013135 2009-05-11 100.25 100.75 93.50 97.25 3925100 78.0824 -0.029925048 2009-05-12 96.50 99.00 94.00 94.50 2770700 75.8744 -0.028277819 2009-05-13 94.75 95.50 88.25 89.00 4618500 71.4584 -0.058201449 2009-05-14 89.00 92.75 87.50 91.75 2712300 73.6664 0.030899097 2009-05-15 94.00 94.00 91.00 92.50 1675400 74.2686 0.008174690 2009-05-18 91.25 97.75 91.00 97.00 3331500 77.8816 0.048647746 2009-05-19 99.25 103.75 98.75 99.50 5343000 79.8889 0.025773739 2009-05-20 100.25 101.00 98.50 100.25 1169700 80.4911 0.007537968 2009-05-21 100.25 100.25 100.25 100.25 0 80.4911 0.000000000 2009-05-22 98.00 99.50 95.75 96.75 2095400 77.6809 -0.034913177 2009-05-25 96.50 97.75 95.50 96.00 1016600 77.0787 -0.007752227 2009-05-26 94.75 96.75 90.75 96.00 3642600 77.0787 0.000000000 2009-05-27 97.50 98.00 96.75 97.50 3729400 78.2831 0.015625588 2009-05-28 96.25 99.00 96.00 98.00 3575300 78.6845 0.005127543 2009-05-29 99.25 100.00 95.25 95.50 3396900 76.6773 -0.025509471 2009-06-01 97.00 100.75 97.00 100.75 1963400 80.8925 0.054973245 2009-06-02 98.00 99.25 95.75 98.00 3547300 78.6845 -0.027295485 2009-06-03 98.75 98.75 95.75 96.75 1865100 77.6809 -0.012754736 2009-06-04 97.25 98.00 96.75 98.00 2496300 78.6845 0.012919521 2009-06-05 98.75 102.25 98.50 100.25 3226800 80.4911 0.022960049 2009-06-08 100.25 101.00 97.25 99.50 2333200 79.8889 -0.007481572 2009-06-09 100.25 103.00 100.25 102.25 4285900 82.0969 0.027638383 2009-06-10 103.25 105.00 102.50 103.50 3933000 83.1005 0.012224579 2009-06-11 105.75 109.00 105.50 108.00 7400700 86.7136 0.043478679 2009-06-12 108.50 110.50 107.50 109.25 3325200 87.7172 0.011573732 2009-06-15 108.25 108.25 103.50 104.00 1848400 83.5019 -0.048055569 2009-06-16 103.75 105.00 102.75 102.75 21000 82.4983 -0.012018888 2009-06-17 101.50 102.25 97.50 99.00 4273700 79.4874 -0.036496510 2009-06-18 99.75 100.75 98.25 100.00 1910400 80.2903 0.010100972 2009-06-19 100.00 100.00 100.00 100.00 0 80.2903 0.000000000 2009-06-22 99.00 99.75 94.00 94.50 3168000 75.8744 0.000000000 2009-06-23 94.50 98.75 94.25 97.50 2356000 78.2831 0.000000000 2009-06-24 99.00 102.50 98.00 102.00 2184800 81.8961 0.046153001 2009-06-25 101.50 103.00 100.00 103.00 1950300 82.6990 0.009803886 2009-06-26 105.00 107.25 103.75 104.50 2649900 83.9034 0.014563659 2009-06-29 105.00 109.25 104.50 108.75 2420700 87.3157 0.040669389 2009-06-30 109.75 110.50 107.25 107.75 2999500 86.5128 -0.009195368 2009-07-01 108.50 111.50 108.50 111.00 2335800 89.1223 0.030163167 2009-07-02 110.50 111.00 106.75 108.00 3151600 86.7136 -0.027026906 2009-07-03 108.00 108.50 106.00 107.00 809300 85.9107 -0.009259217 2009-07-06 106.75 107.50 104.75 106.25 2030400 85.3085 -0.007009604 2009-07-07 107.00 109.50 105.75 107.50 2644100 86.3121 0.011764361 2009-07-08 107.00 108.75 106.25 106.75 3189000 85.7099 -0.006977006 2009-07-09 108.50 110.25 108.50 109.00 3032300 87.5165 0.021078078 2009-07-10 109.25 111.50 108.25 109.25 2637000 87.7172 0.002293282 2009-07-13 108.75 111.25 106.75 110.00 1901300 88.3194 0.006865244 2009-07-14 111.25 112.00 109.25 110.75 2061800 88.9215 0.006817302 2009-07-15 112.00 116.75 111.25 116.75 4185600 93.7390 0.054176999 2009-07-16 125.00 130.50 124.25 127.50 9537100 102.3702 0.092076937 2009-07-17 129.00 131.00 126.25 129.75 2709700 104.1767 0.017646737 2009-07-20 130.00 132.00 129.50 131.00 1762400 105.1803 0.009633632 2009-07-21 131.50 132.25 126.50 127.25 3644800 102.1695 -0.028625132 2009-07-22 127.50 132.25 127.50 130.75 4810100 104.9796 0.027504294 2009-07-23 131.25 131.25 126.75 130.00 3299000 104.3774 -0.005736353 2009-07-24 129.00 133.50 129.00 133.00 52200 106.7861 0.023076835 2009-07-27 134.50 134.75 130.00 132.00 2038900 105.9832 -0.007518769 2009-07-28 132.00 132.75 128.75 130.00 2058000 104.3774 -0.015151458 2009-07-29 130.00 131.50 127.00 128.25 2245700 102.9724 -0.013460768 2009-07-30 130.25 134.25 129.25 134.00 3305500 107.5890 0.044833373 2009-07-31 133.25 138.25 133.00 135.00 3155600 108.3920 0.007463588 2009-08-03 135.00 138.00 134.00 137.25 1916800 110.1985 0.016666359 2009-08-04 136.75 136.75 131.00 132.50 2139700 106.3847 -0.034608457 2009-08-05 132.00 136.00 132.00 134.50 2780800 107.9905 0.015094276 2009-08-06 135.50 139.25 135.00 136.00 2847500 109.1949 0.011152833 2009-08-07 135.25 141.00 134.50 140.00 3169600 112.4065 0.029411630 2009-08-10 139.75 139.75 137.75 139.00 1840700 111.6036 -0.007142825 2009-08-11 138.75 140.00 135.00 135.25 2143500 108.5927 -0.026978520 2009-08-12 134.75 138.50 134.50 138.50 2653600 111.2021 0.024029240 2009-08-13 139.00 149.75 138.75 143.75 8064400 115.4174 0.037906658 2009-08-14 144.25 148.50 141.50 142.75 40600 114.6145 -0.006956490 2009-08-17 141.25 142.00 137.25 137.50 2820500 110.3992 -0.036778069 2009-08-18 138.00 139.00 134.50 137.25 3389500 110.1985 -0.001817948 2009-08-19 136.00 139.75 134.25 138.50 3337300 111.2021 0.009107202 2009-08-20 141.00 148.25 141.00 147.50 5540400 118.4282 0.064981686 2009-08-21 147.50 154.00 147.25 153.50 5896100 123.2457 0.040678656 2009-08-24 155.50 157.00 150.00 154.00 3100300 123.6471 0.003256909 2009-08-25 151.00 151.00 148.75 149.75 3166000 120.2348 -0.027597089 2009-08-26 148.80 149.80 142.40 146.30 4975000 117.4648 -0.023038255 2009-08-27 144.70 146.30 142.70 145.30 2433000 116.6619 -0.006835239 2009-08-28 147.10 153.50 146.40 152.50 4590400 122.4428 0.049552596 2009-08-31 151.50 152.75 146.80 147.50 2984800 118.4282 -0.032787555 2009-09-01 148.60 148.90 145.10 145.30 3402800 116.6619 -0.014914522 2009-09-02 144.00 146.30 140.50 145.60 3403400 116.9027 0.002064084 2009-09-03 146.10 148.40 144.90 147.00 2835000 118.0268 0.009615689 2009-09-04 149.40 153.25 149.10 153.25 3937700 123.0449 0.042516615
x$Return is a vector, not a data.frame and therefore does not have rownames. Use x["Return"] or as.xts(d)[,"Return"] instead.
Quantiling reps performance
This is a simple question from an R rookie. I need to quantile reps performance based on annual sales but the data is provided in quarterly fashion. Can someone help me optimize the code. Rep Quarter Sales 1 100 1 25 2 100 2 32 3 100 3 40 4 100 4 52 5 101 1 40 6 101 2 23 7 101 3 37 8 101 4 61
This is really guessing, because your question is way too vague - but it sounds like you could use aggregate. set.seed(1) example <- data.frame(Rep=rep(100:104,each=4), Quarter=rep(1:4,5), Sales=sample(100,20,replace=TRUE)) > head(example) Rep Quarter Sales 1 100 1 27 2 100 2 38 3 100 3 58 4 100 4 91 5 101 1 21 6 101 2 90 > aggregate(example$Sales,by=list(Rep=example$Rep),summary) Rep x.Min. x.1st Qu. x.Median x.Mean x.3rd Qu. x.Max. 1 100 27.00 35.25 48.00 53.50 66.25 91.00 2 101 21.00 55.50 78.50 68.25 91.25 95.00 3 102 7.00 15.25 19.50 27.25 31.50 63.00 4 103 39.00 47.25 59.50 58.75 71.00 77.00 5 104 39.00 63.75 75.00 72.25 83.50 100.00 Or using the formula method (thanks #Ferdinand): > aggregate(Sales ~ Rep,summary,data=example) Rep Sales.Min. Sales.1st Qu. Sales.Median Sales.Mean Sales.3rd Qu. Sales.Max. 1 100 27.00 35.25 48.00 53.50 66.25 91.00 2 101 21.00 55.50 78.50 68.25 91.25 95.00 3 102 7.00 15.25 19.50 27.25 31.50 63.00 4 103 39.00 47.25 59.50 58.75 71.00 77.00 5 104 39.00 63.75 75.00 72.25 83.50 100.00 You can also plot the data very easily using boxplot: boxplot(example$Sales~example$Rep)