Crop-row detection of already known plant positions - How to? - r

Through image recognition and segmentation I have already obtained an abstract representation of plants on a field (i. e. I exactly know all the coordinates of all plants in an image).
Now I want to detect the crop-rows in this abstract representation - and can't quite figure out how.
My problems are:
the rows in the images may be a bit rotated and not exactly in north/south orientation (angles may vary between -10° to +10°)
The number of crop-rows per image can vary per image and is not fixed - also it is unknown before processing has taken place
The rotation of the crop-rows may be slightly different in each processed image
I have hundreds of images / representations to be processed (so doing it by hand is obviously not really feasible :-) ), so I would need an algorithm that I can later e.g. put into a loop
Can you perhaps help me with at least a strategy (or code snippets) to do such a crop row detection? Idealy in the end for each crop row I would have the parameters of a linear equation (y=m*x+t), so that abline() can be used, but I am open for anything. In the end it could look like something like this (here purely for illustration purposes done by hand):
Underlying data of the images is here:
structure(c(5278.072, 2632.564, 393.34, 4057.704, 3805.599, 611.269,
1823.835, 3359.069, 3598.284, 5262.873, 2069.963, 1579.745, 4539.584,
3579.977, 4296.46, 1831.153, 2333.835, 1126.639, 152.948, 4030.205,
3368.738, 2066.733, 855.111, 2579.665, 3092.37, 1318.357, 1109.438,
3578.606, 375.756, 3796.788, 4520.064, 1807.36, 5001.773, 87.272,
4033.594, 836.708, 639.13, 3105.628, 1569.256, 2831.851, 826.444,
3557.598, 1078.643, 576.266, 4789.585, 3091.929, 5239.658, 1099.954,
1807.972, 2534.677, 4271.841, 5019.276, 2053.246, 1536.071, 3347.644,
4019.766, 3793.392, 5257.628, 604.323, 2561.307, 1792.665, 884.25,
109.456, 3066.108, 3750.833, 4511.819, 2815.08, 119.468, 4499.801,
2582.512, 2822.354, 3773.842, 1054.719, 4251.171, 4002.476, 2018.277,
1775.284, 4959.269, 2541.009, 4742.312, 2265.149, 3071.313, 1779.218,
3972.64, 2822.409, 5217.848, 1265.449, 1522.899, 3057.732, 5364.729,
346.341, 4226.012, 3287.299, 1767.18, 3991.963, 1811.498, 2785.251,
4488.214, 822.509, 2016.435, 3022.344, 2528.079, 4470.315, 3017.716,
572.771, 97.748, 5168.119, 4199.643, 2006.285, 3946.505, 2771.626,
3495.94, 1745.531, 3734.241, 3265.819, 4963.116, 1058.788, 300.408,
1252.845, 4453, 5411.107, 2768.93, 557.806, 2004.424, 2218.582,
4214.073, 4698.292, 5149.238, 4953.886, 1238.343, 3502.518, 2753.044,
5417.502, 1031.945, 2518.901, 1483.487, 4450.737, 2258.484, 289.261,
2987.945, 5156.371, 4171.407, 1995.901, 781.96, 3918.94, 1974.667,
316.758, 1470.993, 5160.868, 3237.828, 521.251, 787.228, 1039.416,
1202.261, 3456.837, 4148.167, 2200.492, 2720.912, 4915.451, 3902.744,
4435.419, 1209.418, 1471.057, 4641.269, 3913.51, 5412.672, 1953.878,
2220.277, 4911.249, 1006.368, 2974.173, 4410.827, 1688.391, 293.729,
1462.871, 4618.785, 5150.904, 2689.061, 1952.56, 5389.383, 2176.387,
995.073, 4125.245, 498.978, 5137.266, 5358.118, 1444.34, 1674.431,
2689.288, 2465.351, 4566.352, 765.125, 1196.984, 1687.859, 258.247,
1914.911, 4575.408, 3421.147, 495.879, 979.079, 1922.943, 4097.704,
737.439, 3410.562, 234.74, 2159.697, 471.983, 1418.991, 2440.575,
1942.708, 1162.525, 5312.409, 2162.656, 5059.814, 1411.412, 4558.905,
247.618, 4319.106, 3411.827, 1786.69, 1670.462, 1180.524, 1640.636,
4715.993, 3576.548, 3566.57, 3589.872, 3565.564, 3531.571, 3415.178,
3511.07, 3510.051, 3487.762, 3470.791, 3443.062, 3369.329, 3386.999,
3387.786, 3277.473, 3376.266, 3421.932, 3387.869, 3367.994, 3346.403,
3259.785, 3296.081, 3297.633, 3285.163, 3300.119, 2941.504, 3264.344,
3277.9, 3235.499, 3198.869, 3235.508, 3156.907, 3221.313, 3123.96,
3165.979, 3186.806, 3148.158, 3129.906, 3035.963, 2987.899, 3053.684,
3050.107, 3052.643, 3037.767, 3037.525, 2994.456, 3006.454, 2960.606,
2973.443, 2919.843, 2917.246, 2939.87, 2914.804, 2886.588, 2920.769,
2906.616, 2908.866, 2868.052, 2885.769, 2860.088, 2801.168, 2853.439,
2853.863, 2847.141, 2805.677, 2806.183, 2718.094, 2661.652, 2695.19,
2656.518, 2612.372, 2603.286, 2602.449, 2591.63, 2595.714, 2593.287,
2575.333, 2572.15, 2476.559, 2435.917, 2538.626, 2514.215, 2458.875,
2477.5, 2385.366, 2421.47, 2220.899, 2397.842, 2396.848, 2393.501,
2352.039, 2292.429, 2315.84, 2328.682, 2256.508, 2236.925, 2192.809,
2241.279, 2144.107, 2195.016, 2185.86, 2112.28, 2098.085, 2020.843,
1971.232, 1979.691, 1968.859, 1943.755, 1974.743, 1891.801, 1944.186,
1951.423, 1872.022, 1928.441, 1880.504, 1912.82, 1893.822, 1878.889,
1850.38, 1834.762, 1851.886, 1806.117, 1776.713, 1682.26, 1733.805,
1714.941, 1700.778, 1686.258, 1703.367, 1549.601, 1682.525, 1563.277,
1632.103, 1609.4, 1621.888, 1587.126, 1545.346, 1537.933, 1542.424,
1366.974, 1494.822, 1498.618, 1494.055, 1450.098, 1407.89, 1345.613,
1388.68, 1380.527, 1368.772, 1372.391, 1161.35, 1297.577, 1312.849,
1304.972, 1286.721, 1292.485, 1257.53, 1241.146, 1263.164, 1217.146,
1226.615, 993.046, 1166.837, 1112.254, 1072.249, 1117.723, 1061.758,
1098.207, 1084.597, 1059.916, 1059.685, 1063.814, 1054.735, 944.2,
982.653, 963.989, 969.55, 941.066, 907.014, 930.988, 776.849,
877.918, 889.259, 805.872, 831.361, 803.752, 786.654, 791.649,
814.271, 794.444, 776.833, 694.969, 664.718, 653.238, 661.703,
652.696, 655.997, 637.118, 539.101, 555.694, 491.482, 459.712,
453.73, 490.567, 391.441, 409.506, 319.697, 391.505, 390.46,
308.658, 310.59, 285.799, 268.86, 245.89, 195.933, 243.418, 214.203,
172.129, 173.754, 191.456, 194.795, 98.098, 99.4479999999999,
62.1419999999998), .Dim = c(224L, 2L))

Here is something that may help:
For each detected plant point, find the closest neighboring plant. Hopefully this finds a plant in the same crop row more often than not. If it's known a priori that images are roughly in north/south orientation, we should prefer looking more in the vertical direction to choose neighboring plants. One way to do that is to redefine "distance" for the nearest neighbor search as something anisotropic like
distance = 10 * (x0 - x1)² + (y0 - y1)²
Here is a plot of what this produces, making a line segment between each plant and its nearest neighbor:
It's not perfect, but could be a useful start. Most crop rows are lucky enough that a run of 4 or more plants are correctly chained together.
A thought on a possible strategy from here:
Identify the connected components, the "chains" of plants.
For each chain, regress a best fit line by least squares. Or better yet, use the RANSAC algorithm so that the fit robustly ignores a single stray plant in an otherwise colinear chain.
Again using the rough north/south orientation, consider the best fit line "valid" only if it's close enough to vertical. Supposing it is valid, find all plants that are close to the best fit line. If many plants are close, then the best fit line is likely a crop row.

Related

Incomplete Expression in R

I'm currently running a time series script in R-Markdown where I pass the values of Percent Use and another vector of the time values. I am processing the two separate vectors with the regular c() function within r. The percentage vector is able to be passed through when compilining like normal, however I am running into trouble with the date/time vector. The length of both vectors are 749, the percentage vector just has values 0-100 passed within them. THe date/time vector has strings passed into them as such:
dt=c('2022-06-19 14:05:00.0','2022-06-19 14:06:00.0', ....
If I only pass a few arguments into the dt vector, it will compile regularly, however, once I increase the size to around half of what it needs to be I start getting the following error:
Error: Incomplete expression: dt=c('2022-06-19 12:40:00.0','2022-06-19 12:41:00.0','2022-06-19 12:42:00.0','2022-06-19 12:43:00.0','2022-06-19 12:44:00.0','2022-06-19 12:45:00.0','2022-06-19 12:46:00.0','2022-06-19 12:47:00.0','2022-06-19 12:48:00.0','2022-06-19 12:49:00.0','2022-06-19 12:50:00.0','2022-06-19 12:51:00.0','2022-06-19 12:52:00.0','2022-06-19 12:53:00.0','2022-06-19 12:54:00.0','2022-06-19 12:55:00.0','2022-06-19 12:56:00.0','2022-06-19 12:57:00.0','2022-06-19 12:58:00.0','2022-06-19 12:59:00.0','2022-06-19 13:00:00.0','2022-06-19 13:01:00.0','2022-06-19 13:02:00.0','2022-06-19 13:03:00.0','2022-06-19 13:04:00.0','2022-06-19 13:05:00.0','2022-06-19 13:06:00.0','2022-06-19 13:07:00.0','2022-06-19 13:08:00.0','2022-06-19 13:09:00.0','2022-06-19 13:10:00.0','2022-06-19 13:11:00.0','2022-06-19 13:12:00.0','2022-06-19 13:13:00.0','2022-06-19 13:14:00.0','2022-06-19 13:15:00.0','2022-06-19 13:16:00.0','2022-06-19 13:17:00.0','2022-06-19 13:18:00.0','2022-06-19 13:19:00.0','2022
At first I believed it could be a parenthesis in the wrong place, however, there is no mistakes with that. I've looked at other articles with somewhat similar issues and have seen a concept of a maximum size vector allowed, however the percentage vector was able to pass all 700. Is there a way to bypass this error, I feel that it is a memory/storage issue with R.
The full code is a lot but it is:
dt=c('2022-06-19 12:40:00.0','2022-06-19 12:41:00.0','2022-06-19 12:42:00.0','2022-06-19 12:43:00.0','2022-06-19 12:44:00.0','2022-06-19 12:45:00.0','2022-06-19 12:46:00.0','2022-06-19 12:47:00.0','2022-06-19 12:48:00.0','2022-06-19 12:49:00.0','2022-06-19 12:50:00.0','2022-06-19 12:51:00.0','2022-06-19 12:52:00.0','2022-06-19 12:53:00.0','2022-06-19 12:54:00.0','2022-06-19 12:55:00.0','2022-06-19 12:56:00.0','2022-06-19 12:57:00.0','2022-06-19 12:58:00.0','2022-06-19 12:59:00.0','2022-06-19 13:00:00.0','2022-06-19 13:01:00.0','2022-06-19 13:02:00.0','2022-06-19 13:03:00.0','2022-06-19 13:04:00.0','2022-06-19 13:05:00.0','2022-06-19 13:06:00.0','2022-06-19 13:07:00.0','2022-06-19 13:08:00.0','2022-06-19 13:09:00.0','2022-06-19 13:10:00.0','2022-06-19 13:11:00.0','2022-06-19 13:12:00.0','2022-06-19 13:13:00.0','2022-06-19 13:14:00.0','2022-06-19 13:15:00.0','2022-06-19 13:16:00.0','2022-06-19 13:17:00.0','2022-06-19 13:18:00.0','2022-06-19 13:19:00.0','2022-06-19 13:20:00.0','2022-06-19 13:21:00.0','2022-06-19 13:22:00.0','2022-06-19 13:23:00.0','2022-06-19 13:24:00.0','2022-06-19 13:25:00.0','2022-06-19 13:26:00.0','2022-06-19 13:27:00.0','2022-06-19 13:28:00.0','2022-06-19 13:29:00.0','2022-06-19 13:30:00.0','2022-06-19 13:31:00.0','2022-06-19 13:32:00.0','2022-06-19 13:33:00.0','2022-06-19 13:34:00.0','2022-06-19 13:35:00.0','2022-06-19 13:36:00.0','2022-06-19 13:37:00.0','2022-06-19 13:38:00.0','2022-06-19 13:39:00.0','2022-06-19 13:40:00.0','2022-06-19 13:41:00.0','2022-06-19 13:42:00.0','2022-06-19 13:43:00.0','2022-06-19 13:44:00.0','2022-06-19 13:45:00.0','2022-06-19 13:46:00.0','2022-06-19 13:47:00.0','2022-06-19 13:48:00.0','2022-06-19 13:49:00.0','2022-06-19 13:50:00.0','2022-06-19 13:51:00.0','2022-06-19 13:52:00.0','2022-06-19 13:53:00.0','2022-06-19 13:54:00.0','2022-06-19 13:55:00.0','2022-06-19 13:56:00.0','2022-06-19 13:57:00.0','2022-06-19 13:58:00.0','2022-06-19 13:59:00.0','2022-06-19 14:00:00.0','2022-06-19 14:01:00.0','2022-06-19 14:02:00.0','2022-06-19 14:03:00.0','2022-06-19 14:04:00.0','2022-06-19 14:05:00.0','2022-06-19 14:06:00.0','2022-06-19 14:07:00.0','2022-06-19 14:08:00.0','2022-06-19 14:09:00.0','2022-06-19 14:10:00.0','2022-06-19 14:11:00.0','2022-06-19 14:12:00.0','2022-06-19 14:13:00.0','2022-06-19 14:14:00.0','2022-06-19 14:15:00.0','2022-06-19 14:16:00.0','2022-06-19 14:17:00.0','2022-06-19 14:18:00.0','2022-06-19 14:19:00.0','2022-06-19 14:20:00.0','2022-06-19 14:21:00.0','2022-06-19 14:22:00.0','2022-06-19 14:23:00.0','2022-06-19 14:24:00.0','2022-06-19 14:25:00.0','2022-06-19 14:26:00.0','2022-06-19 14:27:00.0','2022-06-19 14:28:00.0','2022-06-19 14:29:00.0','2022-06-19 14:30:00.0','2022-06-19 14:31:00.0','2022-06-19 14:32:00.0','2022-06-19 14:33:00.0','2022-06-19 14:34:00.0','2022-06-19 14:35:00.0','2022-06-19 14:36:00.0','2022-06-19 14:37:00.0','2022-06-19 14:38:00.0','2022-06-19 14:39:00.0','2022-06-19 14:40:00.0','2022-06-19 14:41:00.0','2022-06-19 14:42:00.0','2022-06-19 14:43:00.0','2022-06-19 14:44:00.0','2022-06-19 14:45:00.0','2022-06-19 14:46:00.0','2022-06-19 14:47:00.0','2022-06-19 14:48:00.0','2022-06-19 14:49:00.0','2022-06-19 14:50:00.0','2022-06-19 14:51:00.0','2022-06-19 14:52:00.0','2022-06-19 14:53:00.0','2022-06-19 14:54:00.0','2022-06-19 14:55:00.0','2022-06-19 14:56:00.0','2022-06-19 14:57:00.0','2022-06-19 14:58:00.0','2022-06-19 14:59:00.0','2022-06-19 15:00:00.0','2022-06-19 15:01:00.0','2022-06-19 15:02:00.0','2022-06-19 15:03:00.0','2022-06-19 15:04:00.0','2022-06-19 15:05:00.0','2022-06-19 15:06:00.0','2022-06-19 15:07:00.0','2022-06-19 15:08:00.0','2022-06-19 15:09:00.0','2022-06-19 15:10:00.0','2022-06-19 15:11:00.0','2022-06-19 15:12:00.0','2022-06-19 15:13:00.0','2022-06-19 15:14:00.0','2022-06-19 15:15:00.0','2022-06-19 15:16:00.0','2022-06-19 15:17:00.0','2022-06-19 15:18:00.0','2022-06-19 15:19:00.0','2022-06-19 15:20:00.0','2022-06-19 15:21:00.0','2022-06-19 15:22:00.0','2022-06-19 15:23:00.0','2022-06-19 15:24:00.0','2022-06-19 15:25:00.0','2022-06-19 15:26:00.0','2022-06-19 15:27:00.0','2022-06-19 15:28:00.0','2022-06-19 15:29:00.0','2022-06-19 15:30:00.0','2022-06-19 15:31:00.0','2022-06-19 15:32:00.0','2022-06-19 15:33:00.0','2022-06-19 15:34:00.0','2022-06-19 15:35:00.0','2022-06-19 15:36:00.0','2022-06-19 15:37:00.0','2022-06-19 15:38:00.0','2022-06-19 15:39:00.0','2022-06-19 15:40:00.0','2022-06-19 15:41:00.0','2022-06-19 15:42:00.0','2022-06-19 15:43:00.0','2022-06-19 15:44:00.0','2022-06-19 15:45:00.0','2022-06-19 15:46:00.0','2022-06-19 15:47:00.0','2022-06-19 15:48:00.0','2022-06-19 15:49:00.0','2022-06-19 15:50:00.0','2022-06-19 15:51:00.0','2022-06-19 15:52:00.0','2022-06-19 15:53:00.0','2022-06-19 15:54:00.0','2022-06-19 15:55:00.0','2022-06-19 15:56:00.0','2022-06-19 15:57:00.0','2022-06-19 15:58:00.0','2022-06-19 15:59:00.0','2022-06-19 16:00:00.0','2022-06-19 16:01:00.0','2022-06-19 16:02:00.0','2022-06-19 16:03:00.0','2022-06-19 16:04:00.0','2022-06-19 16:05:00.0','2022-06-19 16:06:00.0','2022-06-19 16:07:00.0','2022-06-19 16:08:00.0','2022-06-19 16:09:00.0','2022-06-19 16:10:00.0','2022-06-19 16:11:00.0','2022-06-19 16:12:00.0','2022-06-19 16:13:00.0','2022-06-19 16:14:00.0','2022-06-19 16:15:00.0','2022-06-19 16:16:00.0','2022-06-19 16:17:00.0','2022-06-19 16:18:00.0','2022-06-19 16:19:00.0','2022-06-19 16:20:00.0','2022-06-19 16:21:00.0','2022-06-19 16:22:00.0','2022-06-19 16:23:00.0','2022-06-19 16:24:00.0','2022-06-19 16:25:00.0','2022-06-19 16:26:00.0','2022-06-19 16:27:00.0','2022-06-19 16:28:00.0','2022-06-19 16:29:00.0','2022-06-19 16:30:00.0','2022-06-19 16:31:00.0','2022-06-19 16:32:00.0','2022-06-19 16:33:00.0','2022-06-19 16:34:00.0','2022-06-19 16:35:00.0','2022-06-19 16:36:00.0','2022-06-19 16:37:00.0','2022-06-19 16:38:00.0','2022-06-19 16:39:00.0','2022-06-19 16:40:00.0','2022-06-19 16:41:00.0','2022-06-19 16:42:00.0','2022-06-19 16:43:00.0','2022-06-19 16:44:00.0','2022-06-19 16:45:00.0','2022-06-19 16:46:00.0','2022-06-19 16:47:00.0','2022-06-19 16:48:00.0','2022-06-19 16:49:00.0','2022-06-19 16:50:00.0','2022-06-19 16:51:00.0','2022-06-19 16:52:00.0','2022-06-19 16:53:00.0','2022-06-19 16:54:00.0','2022-06-19 16:55:00.0','2022-06-19 16:56:00.0','2022-06-19 16:57:00.0','2022-06-19 16:58:00.0','2022-06-19 16:59:00.0','2022-06-19 17:00:00.0','2022-06-19 17:01:00.0','2022-06-19 17:02:00.0','2022-06-19 17:03:00.0','2022-06-19 17:04:00.0','2022-06-19 17:05:00.0','2022-06-19 17:06:00.0','2022-06-19 17:07:00.0','2022-06-19 17:08:00.0','2022-06-19 17:09:00.0','2022-06-19 17:10:00.0','2022-06-19 17:11:00.0','2022-06-19 17:12:00.0','2022-06-19 17:13:00.0','2022-06-19 17:14:00.0','2022-06-19 17:15:00.0','2022-06-19 17:16:00.0','2022-06-19 17:17:00.0','2022-06-19 17:18:00.0','2022-06-19 17:19:00.0','2022-06-19 17:20:00.0','2022-06-19 17:21:00.0','2022-06-19 17:22:00.0','2022-06-19 17:23:00.0','2022-06-19 17:24:00.0','2022-06-19 17:25:00.0','2022-06-19 17:26:00.0','2022-06-19 17:27:00.0','2022-06-19 17:28:00.0','2022-06-19 17:29:00.0','2022-06-19 17:30:00.0','2022-06-19 17:31:00.0','2022-06-19 17:32:00.0','2022-06-19 17:33:00.0','2022-06-19 17:34:00.0','2022-06-19 17:35:00.0','2022-06-19 17:36:00.0','2022-06-19 17:37:00.0','2022-06-19 17:38:00.0','2022-06-19 17:39:00.0','2022-06-19 17:40:00.0','2022-06-19 17:41:00.0','2022-06-19 17:42:00.0','2022-06-19 17:43:00.0','2022-06-19 17:44:00.0','2022-06-19 17:45:00.0','2022-06-19 17:46:00.0','2022-06-19 17:47:00.0','2022-06-19 17:48:00.0','2022-06-19 17:49:00.0','2022-06-19 17:50:00.0','2022-06-19 17:51:00.0','2022-06-19 17:52:00.0','2022-06-19 17:53:00.0','2022-06-19 17:54:00.0','2022-06-19 17:55:00.0','2022-06-19 17:56:00.0','2022-06-19 17:57:00.0','2022-06-19 17:58:00.0','2022-06-19 17:59:00.0','2022-06-19 18:00:00.0','2022-06-19 18:01:00.0','2022-06-19 18:02:00.0','2022-06-19 18:03:00.0','2022-06-19 18:04:00.0','2022-06-19 18:05:00.0','2022-06-19 18:06:00.0','2022-06-19 18:07:00.0','2022-06-19 18:08:00.0','2022-06-19 18:09:00.0','2022-06-19 18:10:00.0','2022-06-19 18:11:00.0','2022-06-19 18:12:00.0','2022-06-19 18:13:00.0','2022-06-19 18:14:00.0','2022-06-19 18:15:00.0','2022-06-19 18:16:00.0','2022-06-19 18:17:00.0','2022-06-19 18:18:00.0','2022-06-19 18:19:00.0','2022-06-19 18:20:00.0','2022-06-19 18:21:00.0','2022-06-19 18:22:00.0','2022-06-19 18:23:00.0','2022-06-19 18:24:00.0','2022-06-19 18:25:00.0','2022-06-19 18:26:00.0','2022-06-19 18:27:00.0','2022-06-19 18:28:00.0','2022-06-19 18:29:00.0','2022-06-19 18:30:00.0','2022-06-19 18:31:00.0','2022-06-19 18:32:00.0','2022-06-19 18:33:00.0','2022-06-19 18:34:00.0','2022-06-19 18:35:00.0','2022-06-19 18:36:00.0','2022-06-19 18:37:00.0','2022-06-19 18:38:00.0','2022-06-19 18:39:00.0','2022-06-19 18:40:00.0','2022-06-19 18:41:00.0','2022-06-19 18:42:00.0','2022-06-19 18:43:00.0','2022-06-19 18:44:00.0','2022-06-19 18:45:00.0','2022-06-19 18:46:00.0','2022-06-19 18:47:00.0','2022-06-19 18:48:00.0','2022-06-19 18:49:00.0','2022-06-19 18:50:00.0','2022-06-19 18:51:00.0','2022-06-19 18:52:00.0','2022-06-19 18:53:00.0','2022-06-19 18:54:00.0','2022-06-19 18:55:00.0','2022-06-19 18:56:00.0','2022-06-19 18:57:00.0','2022-06-19 18:58:00.0','2022-06-19 18:59:00.0','2022-06-19 19:00:00.0','2022-06-19 19:01:00.0','2022-06-19 19:02:00.0','2022-06-19 19:03:00.0','2022-06-19 19:04:00.0','2022-06-19 19:05:00.0','2022-06-19 19:06:00.0','2022-06-19 19:07:00.0','2022-06-19 19:08:00.0','2022-06-19 19:09:00.0','2022-06-19 19:10:00.0','2022-06-19 19:11:00.0','2022-06-19 19:12:00.0','2022-06-19 19:13:00.0','2022-06-19 19:14:00.0','2022-06-19 19:15:00.0','2022-06-19 19:16:00.0','2022-06-19 19:17:00.0','2022-06-19 19:18:00.0','2022-06-19 19:19:00.0','2022-06-19 19:20:00.0','2022-06-19 19:21:00.0','2022-06-19 19:22:00.0','2022-06-19 19:23:00.0','2022-06-19 19:24:00.0','2022-06-19 19:25:00.0','2022-06-19 19:26:00.0','2022-06-19 19:27:00.0','2022-06-19 19:28:00.0','2022-06-19 19:29:00.0','2022-06-19 19:30:00.0','2022-06-19 19:31:00.0','2022-06-19 19:32:00.0','2022-06-19 19:33:00.0','2022-06-19 19:34:00.0','2022-06-19 19:35:00.0','2022-06-19 19:36:00.0','2022-06-19 19:37:00.0','2022-06-19 19:38:00.0','2022-06-19 19:39:00.0','2022-06-19 19:40:00.0','2022-06-19 19:41:00.0','2022-06-19 19:42:00.0','2022-06-19 19:43:00.0','2022-06-19 19:44:00.0','2022-06-19 19:45:00.0','2022-06-19 19:46:00.0','2022-06-19 19:47:00.0','2022-06-19 19:48:00.0','2022-06-19 19:49:00.0','2022-06-19 19:50:00.0','2022-06-19 19:51:00.0','2022-06-19 19:52:00.0','2022-06-19 19:53:00.0','2022-06-19 19:54:00.0','2022-06-19 19:55:00.0','2022-06-19 19:56:00.0','2022-06-19 19:57:00.0','2022-06-19 19:58:00.0','2022-06-19 19:59:00.0','2022-06-19 20:00:00.0','2022-06-19 20:01:00.0','2022-06-19 20:02:00.0','2022-06-19 20:03:00.0','2022-06-19 20:04:00.0','2022-06-19 20:05:00.0','2022-06-19 20:06:00.0','2022-06-19 20:07:00.0','2022-06-19 20:08:00.0','2022-06-19 20:09:00.0','2022-06-19 20:10:00.0','2022-06-19 20:11:00.0','2022-06-19 20:12:00.0','2022-06-19 20:13:00.0','2022-06-19 20:14:00.0','2022-06-19 20:15:00.0','2022-06-19 20:16:00.0','2022-06-19 20:17:00.0','2022-06-19 20:18:00.0','2022-06-19 20:19:00.0','2022-06-19 20:20:00.0','2022-06-19 20:21:00.0','2022-06-19 20:22:00.0','2022-06-19 20:23:00.0','2022-06-19 20:24:00.0','2022-06-19 20:25:00.0','2022-06-19 20:26:00.0','2022-06-19 20:27:00.0','2022-06-19 20:28:00.0','2022-06-19 20:29:00.0','2022-06-19 20:30:00.0','2022-06-19 20:31:00.0','2022-06-19 20:32:00.0','2022-06-19 20:33:00.0','2022-06-19 20:34:00.0','2022-06-19 20:35:00.0','2022-06-19 20:36:00.0','2022-06-19 20:37:00.0','2022-06-19 20:38:00.0','2022-06-19 20:39:00.0','2022-06-19 20:40:00.0','2022-06-19 20:41:00.0','2022-06-19 20:42:00.0','2022-06-19 20:43:00.0','2022-06-19 20:44:00.0','2022-06-19 20:45:00.0','2022-06-19 20:46:00.0','2022-06-19 20:47:00.0','2022-06-19 20:48:00.0','2022-06-19 20:49:00.0','2022-06-19 20:50:00.0','2022-06-19 20:51:00.0','2022-06-19 20:52:00.0','2022-06-19 20:53:00.0','2022-06-19 20:54:00.0','2022-06-19 20:55:00.0','2022-06-19 20:56:00.0','2022-06-19 20:57:00.0','2022-06-19 20:58:00.0','2022-06-19 20:59:00.0','2022-06-19 21:00:00.0','2022-06-19 21:01:00.0','2022-06-19 21:02:00.0','2022-06-19 21:03:00.0','2022-06-19 21:04:00.0','2022-06-19 21:05:00.0','2022-06-19 21:06:00.0','2022-06-19 21:07:00.0','2022-06-19 21:08:00.0','2022-06-19 21:09:00.0','2022-06-19 21:10:00.0','2022-06-19 21:11:00.0','2022-06-19 21:12:00.0','2022-06-19 21:13:00.0','2022-06-19 21:14:00.0','2022-06-19 21:15:00.0','2022-06-19 21:16:00.0','2022-06-19 21:17:00.0','2022-06-19 21:18:00.0','2022-06-19 21:19:00.0','2022-06-19 21:20:00.0','2022-06-19 21:21:00.0','2022-06-19 21:22:00.0','2022-06-19 21:23:00.0','2022-06-19 21:24:00.0','2022-06-19 21:25:00.0','2022-06-19 21:26:00.0','2022-06-19 21:27:00.0','2022-06-19 21:28:00.0','2022-06-19 21:29:00.0','2022-06-19 21:30:00.0','2022-06-19 21:31:00.0','2022-06-19 21:32:00.0','2022-06-19 21:33:00.0','2022-06-19 21:34:00.0','2022-06-19 21:35:00.0','2022-06-19 21:36:00.0','2022-06-19 21:37:00.0','2022-06-19 21:38:00.0','2022-06-19 21:39:00.0','2022-06-19 21:40:00.0','2022-06-19 21:41:00.0','2022-06-19 21:42:00.0','2022-06-19 21:43:00.0','2022-06-19 21:44:00.0','2022-06-19 21:45:00.0','2022-06-19 21:46:00.0','2022-06-19 21:47:00.0','2022-06-19 21:48:00.0','2022-06-19 21:49:00.0','2022-06-19 21:50:00.0','2022-06-19 21:51:00.0','2022-06-19 21:52:00.0','2022-06-19 21:53:00.0','2022-06-19 21:54:00.0','2022-06-19 21:55:00.0','2022-06-19 21:56:00.0','2022-06-19 21:57:00.0','2022-06-19 21:58:00.0','2022-06-19 21:59:00.0','2022-06-19 22:00:00.0','2022-06-19 22:01:00.0','2022-06-19 22:02:00.0','2022-06-19 22:03:00.0','2022-06-19 22:04:00.0','2022-06-19 22:05:00.0','2022-06-19 22:06:00.0','2022-06-19 22:07:00.0','2022-06-19 22:08:00.0','2022-06-19 22:09:00.0','2022-06-19 22:10:00.0','2022-06-19 22:11:00.0','2022-06-19 22:12:00.0','2022-06-19 22:13:00.0','2022-06-19 22:14:00.0','2022-06-19 22:15:00.0','2022-06-19 22:16:00.0','2022-06-19 22:17:00.0','2022-06-19 22:18:00.0','2022-06-19 22:19:00.0','2022-06-19 22:20:00.0','2022-06-19 22:21:00.0','2022-06-19 22:22:00.0','2022-06-19 22:23:00.0','2022-06-19 22:24:00.0','2022-06-19 22:25:00.0','2022-06-19 22:26:00.0','2022-06-19 22:27:00.0','2022-06-19 22:28:00.0','2022-06-19 22:29:00.0','2022-06-19 22:30:00.0','2022-06-19 22:31:00.0','2022-06-19 22:32:00.0','2022-06-19 22:33:00.0','2022-06-19 22:34:00.0','2022-06-19 22:35:00.0','2022-06-19 22:36:00.0','2022-06-19 22:37:00.0','2022-06-19 22:38:00.0','2022-06-19 22:39:00.0','2022-06-19 22:40:00.0','2022-06-19 22:41:00.0','2022-06-19 22:42:00.0','2022-06-19 22:43:00.0','2022-06-19 22:44:00.0','2022-06-19 22:45:00.0','2022-06-19 22:46:00.0','2022-06-19 22:47:00.0','2022-06-19 22:48:00.0','2022-06-19 22:49:00.0','2022-06-19 22:50:00.0','2022-06-19 22:51:00.0','2022-06-19 22:52:00.0','2022-06-19 22:53:00.0','2022-06-19 22:54:00.0','2022-06-19 22:55:00.0','2022-06-19 22:56:00.0','2022-06-19 22:57:00.0','2022-06-19 22:58:00.0','2022-06-19 22:59:00.0','2022-06-19 23:00:00.0','2022-06-19 23:01:00.0','2022-06-19 23:02:00.0','2022-06-19 23:03:00.0','2022-06-19 23:04:00.0','2022-06-19 23:05:00.0','2022-06-19 23:06:00.0','2022-06-19 23:07:00.0','2022-06-19 23:08:00.0','2022-06-19 23:09:00.0','2022-06-19 23:10:00.0','2022-06-19 23:11:00.0','2022-06-19 23:12:00.0','2022-06-19 23:13:00.0','2022-06-19 23:14:00.0','2022-06-19 23:15:00.0','2022-06-19 23:16:00.0','2022-06-19 23:17:00.0','2022-06-19 23:18:00.0','2022-06-19 23:19:00.0','2022-06-19 23:20:00.0','2022-06-19 23:21:00.0','2022-06-19 23:22:00.0','2022-06-19 23:23:00.')
I can understand saying there is a issue with the quotations, but I cant find it anywhere. It seems as there is a maximum allowed in a vector, if I compile only the first quarter of the entries it works, else wise on R studio it gives an error, and in the terminal it just expects more code so it gives you a + to add more instead of >.

Fitting distributions with R

Good afternoon. I have a vector 'a' containing 16000 values. I get the descriptive statistics with the help of the following:
library(pastecs)
library(timeDate)
stat.desc(a)
skewness(a)
kurtosis(a)
Especially skewness=-0.5012, kurtosis=420.8073 (1)
Then I build a histogram of my empirical data:
hist(a, col="lightblue", breaks = 140, border="white", main="",
xlab="Value",xlim=c(-0.001,0.001))
After this I try to fit a theoretical distribution to my empirical data. I choose Variance-Gamma distribution and try to get its parameter estimates on my data:
library(VarianceGammma)
a_VG<-vgFit(a)
The parameter estimates are the following:
vgC=-11.7485, sigma=0.4446, theta=11.7193, nu=0.1186 (2)
Further, I create a sample from the Variance-Gamma distribution with the parameters from (2)
and build a histogram of created theoretical values:
VG<-rvg(length(a),vgC=-11.7485,sigma=0.4446,theta=11.7193,nu=0.1186)
hist(VG,breaks=140,col="orange",main="",xlab="Value")
Bu the second histogram differs absolutely from the first (empirical) histogram. Moreover, it is built on the basis of the parameters (2), which I got on the empirical data.
What's wrong with my code? How can I fix it?
P.S. When I type dput(a[abs(a) > 5e-4]) I get:
c(0.000801110480004752, 0.000588162271316861, 0.000555169128569233,
0.000502563410256229, 0.000854633994686438, 0.00593622112246628,
-0.000506168123513007, -0.000502909585836875, 0.000720924373137422,
0.00119141739181039, 0.000548159382141478, -0.000516511318695123,
-0.000744590777740584, 0.000595213912401249, 0.000514055190913965,
-0.000589061375421807, -0.00175392114572581, 0.000745548313668465,
-0.00075910234096277, -0.00059987613053103, 0.000583568488865538,
0.00426484136013094, 0.000610760059768012, 0.000575522836335551,
0.000823785810599276, 0.00181936036509178, -0.00073316272551871,
-0.00184238143420679, -0.000519146793923397, -0.00120324664043103,
-0.000882469414168696, -0.00148118339830283, 0.000929612782487155,
0.000565364610238817, 0.000578158613453894, 0.00060479145432879,
-0.00520576206828594, 0.000708404040882016, 0.00105224485893451,
0.000636486872540587, -0.00359655507585543, 0.000769164650506582,
0.000635701125126786, 0.000570489501935612, -0.000641260260277221,
0.000735092947873994, 0.000757195823062773, 0.000556002742616357,
-0.00207489740356159, -0.000553386431560554, 0.000511326871983186,
0.000504591469525195, -0.000749886905655472, -0.0013939718643865,
-0.000513742626250036, -0.00105021597423516, -0.00156667292147716,
0.000864563166150134, 0.00433724128055069, 0.00053855648931922,
-0.00150732363190365, 0.00052621785349416, 0.000987781100809215,
0.000560725818171903, 0.00176012436713435, -0.000594895431092368,
-0.000686229580335151, 0.00138682284509528, -0.000531964338888358,
-0.00179959148771403, 0.000574543871314503, -0.000686996216439084,
-0.000559043343629995, 0.00055881173674166, -0.000636332688477736,
-0.000623778186703561, -0.00173834148094443, -0.000567224129968125,
-0.00122578683434504, 0.00130960156515414, -0.000548203197176633,
-0.000522749285863711, -0.000820371086264871, 0.000756014225812507,
-0.000714081490558627, -0.000617600335221624, 0.000523639760748651,
-0.000578502663833191, 0.00107478825239227, 0.000612725356974764,
-0.00065509337422931, 0.000505887803587513, -0.000566716376848575,
0.000511727090058756, 0.000572807738912218, -0.000756026937699161,
0.000547948751494332, 0.000628323894238392, -0.000541350489317693,
-0.00133529454372372, -0.000590618859845904, -0.000700581963648972,
0.000735987224462775, 0.000528958898682319, 0.000838250041022448,
-0.000519084424130511, -0.00052258402856431, -0.000538130765869838,
-0.000631819887885854, 0.00054800880764283, 0.00266115500510899,
-0.000839092093771754, 0.000559253571783103, -0.000801028189803432,
-0.000608879021022801, -0.000538018076854385, -0.000689859734395171,
0.00329650346269972, 0.000765494493951024, -0.000689450477848297,
-0.000560199139975737, 0.00159082699266122, -0.00208548663121455,
-0.000598493596793759, 0.000563544422691464, 0.000626996183768824,
-0.000653166846808162, -0.000851350174739807, -0.00140687473245116,
-0.000887003220306326, -0.000765614651347946, -0.00100676206277761,
0.000724714394852555, 0.00108872127644233, -0.000678558537305918,
-0.000705087556212902, 0.000544828152248655, -0.000791700964308362,
0.000606125736727137, -0.00119335967326073, 0.00075413211796338,
0.000526038939010931, 0.00086543737231537, -0.000817788712950573,
-0.000584070926663571, 0.000619657281937691, 0.000680783312420274,
-0.000513831718574664, -0.00050972403875349, -0.00114542220685365,
-0.00070564389723593, -0.01057964950882, -0.000610357922434801,
0.000818264221596365, 0.000940825400308043, -0.000726555639413817,
-0.000591089505560305, 0.000564738888193972, -0.00068515060569041,
0.000668920238348747, -0.00110103375121717, -0.0015480433031172,
0.000663030855223568, 0.000500097431997304, -0.000600730311271391,
-0.000672397772962796, -0.000607852365856587, 0.000536711920570809,
0.000595055206488837, 0.000523123873687581, 0.000977280737528119,
0.000616410821629998, 0.000788593666889881, -0.000671642905915704,
0.000717328711735021, -0.000551853104219902, -0.000565153434708421,
-0.000802585212152707, 0.000536342062561701, 0.000682048510343591,
-0.000541902545439399, 0.000779676683974273, 0.000698841439971787,
0.000559313965908359, -0.00064986819016255, 0.000795421518319017,
0.00364973919549527, 0.000669658692276087, 0.00109045476974678,
0.000514411572742901, 0.000503832507211754, -0.000507376233564116,
0.001232871590787, 0.000561820312542594, -0.000501190337518054,
-0.000769036505996468, -0.000695537959007453, -0.000572065848166048,
-0.00167929926328192, 0.000597078186826749, 0.00710238430870014,
0.000745192112519888, -0.00116091022028009, -0.000791139281769659,
-0.00148898466632552, 0.000565144038962018, -0.000514019821833855,
-0.00148427996685285, -0.000822717245339888, -0.00062922111212238,
-0.000636011367371125, 0.00119640327632808, 0.000548455410294579,
0.000652678152560426, 0.000509244387833618, 0.000961872348987924,
0.000662064072514568, -0.00068116858054168, -0.000569930302445343,
0.00188358126928101, 0.00130560555273895, 0.000593470885775105,
0.00160093110088155, 0.000785262438315115, -0.000912313442922752,
0.000609996052359563, 0.000720137994393966, 0.000568163899000496,
0.00128685533068307, -0.000756787473447318, 0.000765932134255465,
0.00064884753100003, 0.000687571386270847, -0.000582094290400903,
-0.000693177295971736, -0.000601776208094762, 0.000503616387996786,
-0.000615095866544735, -0.000799593899689199, 0.000773750859128342,
-0.000522576090260074, 0.000503578107212022, -0.00104492224837571,
0.000547928732299141, 0.00310304337507183, 0.000893382870797765,
-0.000577792878910799, -0.000647710366578735, -0.00061992948706191,
0.000825702487162516, 0.000606579510524341, 0.000552792484727505,
0.000688600840895504, 0.000505093563534231, -0.000728420573667066,
-0.00157924525963438, -0.000603846616019865, -0.000521941317177976,
0.00150498158245682, -0.000584572670337735, 0.000713757870583365,
0.000524287801789924, 0.00107217649464886, 0.00213147531822244,
0.000566012832157625, -0.00069828890607937, 0.000641567963736378,
-0.000509531713644762, -0.000547564140049417, -0.00115275240244728,
0.000560465768010943, -0.000651807371497171, -0.00096487058986483,
0.000753687665266511, -0.000665599418910645, -0.000691278087025182,
-0.000578010050725553, -0.000685833148198256, 0.000698470819832764,
0.00102943368139208, -0.000725840586788706, 0.00125882415960632,
-0.000630791474954151, -0.000764813558678412, -0.000638539347184164,
0.000654486496518558, 0.000547453642294471, 0.000572020020495501,
-0.000605791001705214, 0.00660211658324172, 0.00114928683282756,
0.000985676480677711, -0.000694668292547718, -0.000528955637964401,
0.000647975568638159, 0.00116454536417443, 0.000506748841724303,
-0.000500925156604382, -0.000567015088082101, 0.00128711230206946,
0.000533633762033858, 0.00505991432758357, 0.000518058378462527,
-0.000592822519784875, 0.00177414999018666, 0.00059845426944527,
-0.000511614433724716, 0.0016614697907098, 0.000852196464322219,
0.00241689725305427, -0.000614317948913978, -0.000729717143318709,
-0.000612900648802039, -0.000727983564232204, -0.000694965869158182,
-0.000527752006066251, -0.000584233784708843, 0.000522097476268968,
0.000543092880677776, 0.000947121210698398, -0.00241810275096377,
0.00181893137435019, 0.000931873879297385, 0.000512116215015013,
0.000724985702444059, -0.000566713495050664, 0.000603953591362227
)
After fitting the data look like the following (empirical histogram-blue, theoretical histogram-orange):
The same when include freq=FALSE in hist
This will all be due to anomalous values in a not represented by the histogram you've shown. This could be the cause of both the very high kurtotsis, and the vgFit() algorithm failing to find a good fit.
Type dput(a[abs(a) > 5e-4]) in the console and copy the output into your question. People then may be able to recreate aomething like the vector a without having to get all 16000 values and debug the vgFit issue.
Thanks for the extra data. There are some extreme values in there, but I don;t think those are what is causing the problem in vgFit. Fitting 4 parameters which can be almost any value is difficult, but you can help it along by rescaling your data to something typical. Try this:
b <- (a-mean(a))/sd(a)
vgf <- vgFit(b)
vgf$param
VG <- rvg(16000, param = vgf$param)
VG_rescaled <- VG*sd(a)+mean(a)
hist(VG_rescaled, breaks=140, col="orange", main="", xlab="Value")
and see if the two histograms are close enough now.

Spatial analysis with R package spatstat, sidebar does not show correct values

I'm trying to create a map with the spatstat package of R so that the sidebar shows the values of the third (preferably) or fourth column of my data frame and that the colors are also reflective of that third (or fourth column) chosen.
My script:
x=c(6.839887, 6.671494, 6.651083, 6.655289, 6.591903, 6.653641, 6.661709, 6.671664, 6.660044, 6.624659, 6.648162, 6.536877, 6.654134, 6.674678,6.618935, 6.677705, 6.643918, 6.644119, 6.670517, 6.583619, 6.649991, 6.647649, 6.656308, 6.645772, 6.648740, 6.643103, 6.652199, 6.666641,6.633400, 6.621282, 6.635427, 6.646127, 6.630862, 6.657919, 6.671616, 6.622935, 6.648225, 6.676911, 6.640234, 6.719334, 6.653202, 6.656747,6.724692, 6.639747, 6.630575, 6.657916, 6.618957, 6.640006, 6.645280, 6.614058, 6.576136, 6.631994, 6.617391, 6.782351, 6.620072, 6.661061,6.597216, 6.648755, 6.618436, 6.659507, 6.653993, 6.663255, 6.630893, 6.656322, 6.617265, 6.649022, 6.629346, 6.595224, 6.540263, 6.623435,6.652709, 6.608565, 6.618335, 6.645100, 6.790914, 6.643620, 6.462808, 6.680115, 6.716004, 6.668781, 6.765199, 6.674251, 6.647542, 6.724564,6.724556)
y=c(17.16749, 17.16727, 17.16678, 17.16673, 17.16813, 17.16663, 17.16652, 17.16636, 17.16629, 17.16856, 17.16521, 17.16519, 17.17002, 17.16465,17.17015, 17.16407, 17.16356, 17.17122, 17.16334, 17.17152, 17.16282, 17.16278, 17.16272, 17.17257, 17.16198, 17.17279, 17.16169, 17.16161,17.16146, 17.17352, 17.17389, 17.16076, 17.17420, 17.16046, 17.15917, 17.17571, 17.15895, 17.15881, 17.15860, 17.15827, 17.15797, 17.15776,17.17761, 17.15664, 17.15622, 17.15610, 17.15571, 17.15561, 17.15527,17.15514, 17.15494, 17.15447, 17.15438, 17.18041, 17.18053, 17.15402,17.18090, 17.15384, 17.18121, 17.15355, 17.15352, 17.15349, 17.18213,17.15242, 17.15201, 17.14978, 17.18591, 17.18688, 17.18707, 17.18761,17.14712, 17.18788, 17.18794, 17.14619, 17.18868, 17.14588, 17.14511,17.14471, 17.14440, 17.14430, 17.19116, 17.19140, 17.14222, 17.14123,17.33627)
z=c(32.23228,526.46061, -1300.03539, -376.04329, 139.67322,-913.24800, -526.46061, 354.55511, 483.48424, 161.16141, 182.64960, 419.0196, 75.20866, -225.62598, -1536.40546, -397.53148, -1106.64169, -440.50786, 118.18504,-290.09054, -1471.94089, 440.50786,-848.78343, -1385.98814, -676.87793, -1622.35821, -1450.45271,75.20866, -1557.89365, 161.16141, 376.04329, 354.55511, -32.23228,-1171.10626,-75.20866, 547.94880, -805.80706, 870.27162, -698.36612,-32.23228, -2331.46842, -182.64960, 75.20866, -719.85431,-1837.24009,913.24800, -1106.64169, 698.36612, 483.48424, -676.87793, -3019.09045, 891.75981, 1106.64169, 333.06692, -913.24800,333.06692, 934.73619, 354.55511, 75.20866, -891.75981, -247.11416, -1966.16922, 139.67322, -784.31887, -569.43699, -118.18504,-440.50786, 397.53148, -655.38974, 139.67322, 53.72047, -633.90155,-633.90155, 419.01967, -547.94880, 75.20866, 569.43699, 290.09054, -376.04329, 547.94880, 75.20866, -10.74409, 182.64960,-397.53148, -479.53833 )
w=c(96326.91, 96769.46, 95127.94, 95960.41, 96423.22, 95476.93, 95825.18,96615.67, 96731.03, 96442.47, 96461.73, 96673.36, 96365.44, 96095.53,94914.31, 95941.10, 95302.53, 95902.47, 96403.96, 96037.64, 94972.60,96692.58, 95535.03, 95050.29, 95689.84, 94836.56, 94992.03, 96365.44,94894.87, 96442.47, 96634.90, 96615.67, 96269.09, 95244.36, 96230.54,96788.68, 95573.74, 97076.62, 95670.50, 96269.09, 94193.69, 96134.12,96365.44, 95651.15, 94642.01, 97114.98, 95302.53, 96923.12, 96731.03,95689.84, 93567.91, 97095.80, 97287.46, 96596.43, 95476.93, 96596.43,97134.15, 96615.67, 96365.44, 95496.30, 96076.24, 94525.17, 96423.22,95593.10, 95786.52, 96191.98, 95902.47, 96654.13, 95709.18, 96423.22,96346.17, 95728.52, 95728.52, 96673.36, 95805.85, 96365.44, 96807.89,96557.96, 95960.41, 96788.68, 96365.44, 96288.37, 96461.73,95941.10, 99451.20)
shap.lo=data.frame(x,y,z,w)
library(spatstat)
shap.lo.win <- owin(range(shap.lo[,1]), range(shap.lo[,2]))
centroid.owin(shap.lo.win) ; area.owin(shap.lo.win)
shap.lo.ppp <- as.ppp(shap.lo[,c(1,2,3)], shap.lo.win) # making a ppp object
plot(density(shap.lo.ppp,0.02), col=topo.colors(25), main='', xlab='x',
ylab='y')
points(x, y)
the result is shown below
I would like to know why the sidebar shows different values than the ones shown in the third column of my data frame, that is, in addition to displaying no negative values, shows values much larger than those contained in the third column.
Is it possible to do this, that is, make the colors and the sidebar represent the third or fourth column of the data frame?
I thank the help of all you!
Let me quote directly from the help file for density.ppp:
This function is often misunderstood.
The result of density.ppp is not a spatial smoothing of the
marks or weights attached to the point pattern. To perform
spatial interpolation of values that were observed at the points
of a point pattern, use Smooth.ppp.
The result of density.ppp is not a probability density. It is
an estimate of the intensity function of the point process that
generated the point pattern data. Intensity is the expected
number of random points per unit area. The units of intensity are
“points per unit area”. Intensity is usually a function of
spatial location, and it is this function which is estimated by
density.ppp. The integral of the intensity function over a
spatial region gives the expected number of points falling in this
region.
So try Smooth.ppp (note the upper case S), and see if you can make that produce the results you expected.

Resampling multivariate time series in R

I have a set of bivariate time series and want to resample them to the same length. I thought that it might be a good idea to use the mean length of all time series, since I wanted to avoid that some series will be shortened or extended too much. My first naive idea was using the resample method of the signal package, and resample each dimension of a series separately. I don't like this idea very much, since I have the fear that the alignment between the dimensions might suffer from the independent resampling, but I hoped this effect might be negligible.
My current problem is that the resampling of the data creates artifacts at the end and beginning of a series. It seems that the resample method assumes that the series starts from zero. Now I'm wondering if there is a more suitable resampling method which in the best case is readily available (in R) and maybe also supports bivariate time series.
Plot:
http://i.stack.imgur.com/3OwAt.png
Code example:
example <- c(-2014.1, -2014.1, -2014.1, -2014, -2014, -2013.9, -2013.9,
-2013.7, -2013.5, -2013.4, -2013.1, -2012.9, -2012.6, -2012.4,
-2012, -2011.7, -2011.4, -2011, -2010.5, -2010.1, -2009.5, -2009.1,
-2008.6, -2008, -2007.5, -2006.9, -2006.4, -2005.7, -2005.1,
-2004.4, -2003.7, -2003, -2002.4, -2001.5, -2000.7, -1999.9,
-1999.1, -1998.2, -1997.4, -1996.5, -1995.6, -1994.6, -1993.6,
-1992.6, -1991.7, -1990.7, -1989.7, -1988.9, -1987.9, -1986.9,
-1985.9, -1984.9, -1984, -1983, -1982.1, -1981.1, -1980.1, -1979.2,
-1978.2, -1977.2, -1976.4, -1975.4, -1974.4, -1973.4, -1972.4,
-1971.5, -1970.5, -1969.6, -1968.6, -1967.6, -1966.6, -1965.7,
-1964.7, -1963.9, -1962.9, -1961.9, -1960.9, -1959.9, -1958.9,
-1957.9, -1956.9, -1955.9, -1955, -1954, -1953, -1952.1, -1951.5,
-1951.1, -1950.6, -1950.1, -1949.6, -1949.2, -1948.7, -1948.2,
-1947.9, -1947.4, -1946.9, -1946.4, -1945.9, -1945.4, -1944.9,
-1944.4, -1943.9, -1943.4, -1943, -1942.5, -1942, -1941.5, -1941,
-1940.6, -1940.1, -1939.6, -1939.1, -1938.7, -1938.2, -1937.7,
-1937.2, -1936.7, -1936.2, -1935.7, -1935.4, -1934.9, -1934.4,
-1933.9, -1933.4, -1932.9, -1932.4, -1931.9, -1931.4, -1931,
-1930.5, -1930, -1929.5, -1929, -1928.6, -1928.1, -1927.6, -1927.1,
-1926.6, -1926.2, -1925.7, -1925.2, -1924.7, -1924.4, -1923.9,
-1923.4, -1922.9, -1922.4, -1921.9, -1921.4, -1920.9, -1920.4,
-1919.9, -1919.4, -1919, -1918.5, -1918, -1917.5, -1917, -1916.6,
-1916.1, -1915.6, -1915.1, -1914.6, -1914.2, -1913.7, -1913.2,
-1912.7, -1912.2, -1911.7, -1911.4, -1910.9, -1910.4, -1909.9,
-1909.4, -1908.9, -1908.4, -1907.9, -1907.5, -1906.9, -1906.5,
-1906, -1905.5, -1905, -1904.6, -1904, -1903.6, -1903.1, -1902.7,
-1902.2, -1901.7, -1901.2, -1900.7, -1900.4, -1899.9, -1899.4,
-1898.9, -1898.4, -1897.9, -1897.4, -1896.9, -1896.4, -1895.9,
-1895.2, -1895, -1894.5, -1894, -1893.6, -1893.1, -1892.6, -1892.1,
-1891.6, -1891.2, -1890.7, -1890.2, -1889.7, -1889.2, -1888.9,
-1888.4, -1887.9, -1887.4, -1886.9, -1886.4, -1885.6, -1885.4,
-1884.9, -1884.5, -1884, -1883.5, -1883, -1882.5, -1882.1, -1881.6,
-1881.1, -1880.6, -1880.2, -1879.7, -1879.2, -1878.7, -1878.4,
-1877.9, -1877.4, -1876.9, -1876.1, -1875.6, -1875.1, -1874.6,
-1874.1, -1873.6, -1873.2, -1872.7, -1872.2, -1871.7, -1871.4,
-1870.7, -1870.4, -1869.9, -1869.4, -1868.9, -1868.4, -1867.9,
-1867.4, -1867.2, -1866.4, -1866, -1865.5, -1865, -1864.5, -1864.1,
-1863.6, -1863.1, -1862.6, -1862.1, -1861.7, -1861.2, -1860.7,
-1860.2, -1859.7, -1859.4, -1858.9, -1858.4, -1857.9, -1857.4,
-1856.9, -1856.4, -1855.9, -1855.4, -1854.9, -1854.5, -1854,
-1853.5, -1853.1, -1852.6, -1852.1, -1851.6, -1851.1, -1850.7,
-1850.2, -1849.7, -1849.2)
plot(example, t="l", main="Original")
plot(resample(example,250,length(example)), t="l", main="Resampled")

Manhattan distance in 8 puzzle

Can anybody explain me how to calculate manhattan distance in 8 puzzle problem on this example http://ai.ia.agh.edu.pl/wiki/pl:prolog:pllib:sliding_puzzle ?
How it's calculate this:
a(0,0). a(1,0). a(2,1). a(3,2). a(4,3). a(5,4). a(6,3). a(7,2).
a(8,1). b(0,0). b(1,1). b(2,0). b(3,1). b(4,2). b(5,3). b(6,2).
b(7,3). b(8,2). c(0,0). c(1,2). c(2,1). c(3,0). c(4,1). c(5,2).
c(6,3). c(7,4). c(8,3). d(0,0). d(1,1). d(2,2). d(3,3). d(4,2).
d(5,3). d(6,2). d(7,2). d(8,0). e(0,0). e(1,2). e(2,1). e(3,2).
e(4,1). e(5,2). e(6,1). e(7,2). e(8,1). f(0,0). f(1,3). f(2,2).
f(3,1). f(4,0). f(5,1). f(6,2). f(7,3). f(8,2). g(0,0). g(1,2).
g(2,3). g(3,4). g(4,3). g(5,2). g(6,2). g(7,0). g(8,1). h(0,0).
h(1,3). h(2,3). h(3,3). h(4,2). h(5,1). h(6,0). h(7,1). h(8,2).
i(0,0). i(1,4). i(2,3). i(3,2). i(4,1). i(5,0). i(6,1). i(7,2).
i(8,3).
in this code?
a,b,c,...,i are the fixed cells names. The table is hand-coded to speedup the number of steps required to reach the goal - for instance, take d(8,0)., this only make sense because of goal(1/2/3/8/0/4/7/6/5)., that is, when cell d holds 8, 0 steps are required...

Resources