Related
Background: I'm working on creating data visualizations from water quality data. The code I have works great for the most part, but sometimes we have to drop data from the surface if it's too choppy to get good data, so we end up with data starting at 2m (sometimes 3m) depth. When we drop the values, the interpolation returns NA values at the surface, making the visualizations unusable for our purpose. See images for examples: Example of a good visualization Example of visualization with surface NAs
Example data snip and further explanation below code
The akima::interp function does not allow for extrapolation when using linear interpolation, and the non-linear option isn't appropriate for our data.
I'm looking for a workaround for this. My thoughts were either:
a line of code that does something like: "if minimum depth at station is greater than 1, copy data from minimum depth to all depths between 1 and the minimum" (disclaimer: I know this isn't appropriate for analysis, but for our purposes creating visualizations to show data trends we are okay with this)
something I'm missing within the function that will allow for extrapolation (or using a different linear interpolation function)
Here is the code I have so far (this is taken from within a larger function).
library(akima); library(dplyr)
library("data.table");library(tidyverse);library(naniar)
library(magrittr);library(janitor);library(lubridate);library(wql)
##Example data import
example.data<-structure(list(Station = c(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11,
11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12,
12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14,
14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15,
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 17, 17,
17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
21, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 25, 25, 25, 25, 25,
25, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27,
27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 29,
29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29.5, 29.5, 29.5, 29.5,
29.5, 29.5, 29.5, 29.5, 29.5, 29.5, 29.5, 29.5, 30, 30, 30, 30,
30, 30, 30, 30, 30, 30, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
32, 32, 32, 32, 32, 32, 32, 32, 33, 33, 33, 33, 33, 33, 33, 33,
33, 33, 34, 34, 649, 649, 649, 649, 649, 649, 649, 649, 649,
649, 657, 657, 657, 657, 657, 657, 657, 657, 657, 657), Distance.from.36 = c(127.7053,
127.7053, 127.7053, 127.7053, 127.7053, 127.7053, 127.7053, 127.7053,
127.7053, 127.7053, 125.3243, 125.3243, 125.3243, 125.3243, 125.3243,
125.3243, 125.3243, 125.3243, 125.3243, 125.3243, 119.8957, 119.8957,
119.8957, 119.8957, 119.8957, 119.8957, 119.8957, 119.8957, 119.8957,
119.8957, 119.8957, 119.8957, 119.8957, 119.8957, 119.8957, 119.8957,
115.6252, 115.6252, 115.6252, 115.6252, 115.6252, 115.6252, 115.6252,
115.6252, 115.6252, 115.6252, 115.6252, 115.6252, 110.8977, 110.8977,
110.8977, 110.8977, 110.8977, 110.8977, 110.8977, 110.8977, 110.8977,
110.8977, 104.981, 104.981, 104.981, 104.981, 104.981, 104.981,
104.981, 104.981, 104.981, 104.981, 104.981, 104.981, 104.981,
99.7699, 99.7699, 99.7699, 99.7699, 99.7699, 99.7699, 99.7699,
99.7699, 99.7699, 99.7699, 99.7699, 99.7699, 99.7699, 99.7699,
99.7699, 96.7889, 96.7889, 96.7889, 96.7889, 96.7889, 96.7889,
96.7889, 96.7889, 96.7889, 96.7889, 96.7889, 96.7889, 96.7889,
96.7889, 96.7889, 96.7889, 96.7889, 96.7889, 96.7889, 96.7889,
96.7889, 96.7889, 96.7889, 96.7889, 96.7889, 93.5951, 93.5951,
93.5951, 93.5951, 93.5951, 93.5951, 93.5951, 93.5951, 93.5951,
93.5951, 93.5951, 93.5951, 93.5951, 93.5951, 93.5951, 93.5951,
93.5951, 89.7672, 89.7672, 89.7672, 89.7672, 89.7672, 89.7672,
89.7672, 89.7672, 89.7672, 89.7672, 89.7672, 89.7672, 89.7672,
84.4458, 84.4458, 84.4458, 84.4458, 84.4458, 84.4458, 84.4458,
84.4458, 78.5444, 78.5444, 78.5444, 78.5444, 78.5444, 78.5444,
78.5444, 78.5444, 78.5444, 74.4288, 74.4288, 74.4288, 74.4288,
74.4288, 74.4288, 74.4288, 74.4288, 74.4288, 74.4288, 74.4288,
74.4288, 74.4288, 74.4288, 69.9895, 69.9895, 69.9895, 69.9895,
69.9895, 69.9895, 69.9895, 69.9895, 69.9895, 69.9895, 69.9895,
69.9895, 69.9895, 69.9895, 69.9895, 69.9895, 69.9895, 69.9895,
69.9895, 69.9895, 69.9895, 69.9895, 63.0794, 63.0794, 63.0794,
63.0794, 63.0794, 63.0794, 63.0794, 63.0794, 63.0794, 63.0794,
63.0794, 58.8909, 58.8909, 58.8909, 58.8909, 58.8909, 58.8909,
58.8909, 58.8909, 58.8909, 58.8909, 58.8909, 58.8909, 54.9481,
54.9481, 54.9481, 54.9481, 54.9481, 54.9481, 54.9481, 54.9481,
54.9481, 54.9481, 54.9481, 54.9481, 54.9481, 54.9481, 54.9481,
54.9481, 54.9481, 54.9481, 54.9481, 54.9481, 54.9481, 54.9481,
54.9481, 54.9481, 54.9481, 54.9481, 54.9481, 54.9481, 54.9481,
54.9481, 54.9481, 54.9481, 54.9481, 54.9481, 54.9481, 54.9481,
54.9481, 54.9481, 54.9481, 51.4501, 51.4501, 51.4501, 51.4501,
51.4501, 51.4501, 51.4501, 51.4501, 51.4501, 51.4501, 51.4501,
51.4501, 51.4501, 51.4501, 51.4501, 51.4501, 51.4501, 51.4501,
51.4501, 51.4501, 51.4501, 51.4501, 51.4501, 51.4501, 46.6266,
46.6266, 46.6266, 46.6266, 46.6266, 46.6266, 46.6266, 46.6266,
46.6266, 46.6266, 46.6266, 46.6266, 46.6266, 46.6266, 46.6266,
46.6266, 43.921, 43.921, 43.921, 43.921, 43.921, 43.921, 43.921,
43.921, 43.921, 43.921, 43.921, 43.921, 43.921, 43.921, 43.921,
43.921, 43.921, 39.6557, 39.6557, 39.6557, 39.6557, 39.6557,
39.6557, 39.6557, 39.6557, 39.6557, 39.6557, 39.6557, 39.6557,
39.6557, 37.0911, 37.0911, 37.0911, 37.0911, 37.0911, 37.0911,
37.0911, 37.0911, 32.8382, 32.8382, 32.8382, 32.8382, 32.8382,
32.8382, 28.756, 28.756, 28.756, 28.756, 28.756, 28.756, 28.756,
28.756, 26.1872, 26.1872, 26.1872, 26.1872, 26.1872, 26.1872,
26.1872, 26.1872, 26.1872, 26.1872, 23.5695, 23.5695, 23.5695,
23.5695, 23.5695, 23.5695, 23.5695, 23.5695, 23.5695, 23.5695,
23.5695, 23.5695, 20.2526, 20.2526, 20.2526, 20.2526, 20.2526,
20.2526, 20.2526, 20.2526, 20.2526, 20.2526, 20.2526, 17.564,
17.564, 17.564, 17.564, 17.564, 17.564, 17.564, 17.564, 17.564,
17.564, 17.564, 17.564, 14.7543, 14.7543, 14.7543, 14.7543, 14.7543,
14.7543, 14.7543, 14.7543, 14.7543, 14.7543, 10.6065, 10.6065,
10.6065, 10.6065, 10.6065, 10.6065, 10.6065, 10.6065, 10.6065,
10.6065, 8.1507, 8.1507, 8.1507, 8.1507, 8.1507, 8.1507, 8.1507,
8.1507, 6.8085, 6.8085, 6.8085, 6.8085, 6.8085, 6.8085, 6.8085,
6.8085, 6.8085, 6.8085, 3.529, 3.529, 132.9388, 132.9388, 132.9388,
132.9388, 132.9388, 132.9388, 132.9388, 132.9388, 132.9388, 132.9388,
147.2548, 147.2548, 147.2548, 147.2548, 147.2548, 147.2548, 147.2548,
147.2548, 147.2548, 147.2548), Depth = c(2L, 3L, 4L, 5L, 6L,
7L, 8L, 9L, 10L, 11L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L,
2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L,
16L, 17L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L,
2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 2L, 3L, 4L, 5L, 6L,
7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 2L, 3L, 4L, 5L, 6L,
7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L,
20L, 21L, 22L, 23L, 24L, 25L, 26L, 2L, 3L, 4L, 5L, 6L, 7L, 8L,
9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 2L, 3L, 4L,
5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 2L, 3L, 4L, 5L,
6L, 7L, 8L, 9L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 2L, 3L,
4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 2L, 3L,
4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L,
18L, 19L, 20L, 21L, 22L, 23L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L,
10L, 11L, 12L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L,
13L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L,
16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L,
29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L,
2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L,
16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 2L, 3L, 4L,
5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 2L,
3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L,
17L, 18L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L,
14L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 2L, 3L, 4L, 5L, 6L, 7L,
2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L,
10L, 11L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L,
2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 2L, 3L, 4L, 5L,
6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 2L, 3L, 4L, 5L, 6L, 7L, 8L,
9L, 10L, 11L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 2L, 3L,
4L, 5L, 6L, 7L, 8L, 9L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L,
3L, 4L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 2L, 3L, 4L,
5L, 6L, 7L, 8L, 9L, 10L, 11L), Calc.Chl = c(3.3, 3.2, 3.2, 3.2,
3.2, 3.2, 3.1, 3.1, 3.2, 3.2, 3.4, 3.4, 3.6, 3.6, 3.6, 3.7, 3.5,
3.4, 3.6, 3.6, 3.7, 3.6, 3.6, 3.6, 3.6, 3.6, 3.6, 3.6, 3.5, 3.4,
3.5, 3.5, 3.5, 3.5, 3.5, 3.4, 3.9, 3.9, 3.8, 3.9, 3.8, 3.8, 3.8,
3.8, 3.7, 3.7, 3.7, 3.6, 4.4, 4.4, 4.3, 4.4, 4.3, 4.1, 4.1, 4.1,
4, 4.1, 3.3, 3, 2.9, 2.9, 2.9, 2.8, 2.6, 2.8, 2.8, 2.7, 2.7,
2.7, 2.8, 3.1, 3.1, 2.8, 2.5, 2.5, 2.4, 2.2, 2.2, 2.1, 2, 1.7,
1.9, 2, 2.1, 2.1, 2.2, 2.2, 2, 2, 2, 1.9, 1.9, 1.9, 1.8, 1.7,
1.6, 1.6, 1.6, 1.8, 1.9, 1.9, 1.9, 1.9, 2, 1.9, 2, 2, 2, 2, 2,
1.2, 1.9, 1.9, 1.8, 1.7, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.6, 1.7,
1.4, 1.3, 1.8, 2, 1.2, 1.7, 1.7, 1.6, 1.6, 1.5, 1.5, 1.4, 1.5,
1.7, 1.7, 1.7, 1.7, 2.9, 2.8, 1.8, 1.8, 1.8, 2.2, 2.1, 1.7, 4.5,
3.8, 2.8, 2.3, 2.8, 2.9, 2.6, 2.4, 2.9, 3.8, 3.6, 3.1, 3, 3.1,
3, 2.9, 2.6, 3, 3.1, 2.8, 2.6, 2.8, 2.3, 4, 3.8, 3.2, 2.8, 2.6,
2.5, 2.7, 2.6, 2.5, 2.5, 2.5, 2.6, 2.7, 2.7, 2.6, 2.7, 3, 3,
2.8, 2.8, 2.8, 2.8, 4.1, 4.3, 4.4, 4.3, 4.3, 4.4, 4.6, 4.8, 4.9,
4.8, 4.8, 3.6, 4, 4.2, 4.2, 4, 4.3, 4.9, 5.1, 5.5, 5.5, 5.3,
5.7, 4.1, 5, 4.7, 4.9, 4.9, 5.2, 5.2, 5.2, 5.2, 5, 4.9, 4.9,
5.1, 5.1, 5.3, 5.2, 5.5, 5.6, 5.7, 5.7, 5.3, 5.2, 5.2, 5.4, 5.6,
5.8, 5.8, 5.8, 5.8, 6, 6.1, 6, 6, 6, 5.9, 6, 5.8, 6.1, 6, 4.5,
5, 5.1, 4.5, 4.6, 4.5, 4.5, 4.4, 4.4, 4.5, 4.5, 4.5, 4.4, 4.6,
4.6, 4.7, 4.8, 4.7, 4.9, 4.8, 4.5, 4.9, 5.3, 5.6, 4.1, 4.1, 4.1,
4.2, 4.2, 4.4, 4.4, 4.3, 4.4, 4.4, 4.5, 4.8, 4.7, 4.7, 4.9, 5.1,
4.1, 3.9, 3.9, 3.9, 3.8, 3.8, 3.9, 4, 4.2, 4.3, 4.5, 4.6, 5,
5.1, 5.2, 5.3, 5.2, 6.2, 5.7, 4.5, 4.1, 4.1, 4.2, 4.2, 4.3, 4.3,
4.4, 4.4, 4.4, 4.6, 4.3, 4.2, 4.1, 4.2, 4.2, 4.2, 4.3, 4.3, 4.7,
4.6, 4.6, 4.6, 4.6, 4.6, 4.2, 4.2, 4.2, 4.1, 4.1, 4.3, 4.3, 4.3,
4.8, 4.6, 4.6, 4.6, 4.6, 4.5, 4.4, 4.3, 4.3, 4.4, 4.7, 4.6, 4.7,
4.6, 4.5, 4.4, 4.3, 4.2, 4.3, 4.3, 4.4, 4.5, 5.5, 5.4, 5.3, 5.1,
5, 4.9, 4.9, 5, 5, 5.1, 5, 7.1, 6.9, 6.9, 6.9, 6.8, 6.8, 6.7,
6.5, 6.4, 6.1, 5.5, 5.3, 7.3, 7.2, 7.3, 7.4, 7.1, 6.8, 6.6, 6.4,
6.2, 6, 7.3, 8.2, 8.8, 9.6, 10.4, 10.5, 10.8, 11.1, 11.3, 11.4,
6.7, 6.6, 6.8, 6.9, 6.9, 7.3, 7.6, 7.8, 8.2, 8.2, 8.2, 8.1, 8.1,
8.1, 8.1, 8.1, 8.1, 8.5, 8.3, 8.1, 3.1, 3.1, 3.1, 3.1, 3.2, 3.1,
3.1, 3.2, 3.2, 3.2, 2.1, 2.2, 2.2, 2.3, 2.4, 2.4, 2.2, 2.3, 2.2,
2.1), DO = c(91L, 91L, 91L, 91L, 91L, 91L, 91L, 91L, 91L, 91L,
91L, 91L, 91L, 91L, 91L, 91L, 91L, 91L, 91L, 91L, 91L, 91L, 91L,
91L, 91L, 91L, 91L, 91L, 91L, 91L, 91L, 91L, 91L, 91L, 91L, 91L,
92L, 92L, 92L, 92L, 92L, 92L, 92L, 92L, 92L, 92L, 92L, 92L, 92L,
92L, 92L, 91L, 91L, 91L, 91L, 91L, 91L, 91L, 92L, 91L, 91L, 91L,
91L, 91L, 90L, 90L, 90L, 90L, 90L, 90L, 90L, 91L, 90L, 90L, 89L,
89L, 89L, 89L, 88L, 88L, 88L, 88L, 88L, 88L, 88L, 88L, 89L, 89L,
89L, 88L, 88L, 88L, 88L, 88L, 88L, 87L, 87L, 87L, 87L, 87L, 87L,
87L, 87L, 87L, 87L, 87L, 87L, 87L, 87L, 87L, 87L, 90L, 90L, 89L,
88L, 88L, 88L, 87L, 87L, 87L, 87L, 87L, 87L, 87L, 87L, 87L, 87L,
87L, 88L, 88L, 88L, 87L, 87L, 87L, 87L, 86L, 86L, 86L, 86L, 86L,
86L, 89L, 87L, 86L, 86L, 86L, 86L, 86L, 85L, 89L, 87L, 86L, 86L,
86L, 86L, 86L, 86L, 85L, 87L, 87L, 86L, 86L, 86L, 86L, 86L, 86L,
85L, 85L, 85L, 85L, 85L, 85L, 88L, 87L, 87L, 86L, 86L, 86L, 86L,
85L, 85L, 85L, 85L, 85L, 85L, 85L, 85L, 85L, 85L, 85L, 85L, 85L,
85L, 85L, 87L, 87L, 86L, 86L, 86L, 85L, 85L, 85L, 85L, 85L, 85L,
84L, 84L, 84L, 84L, 84L, 84L, 84L, 84L, 84L, 84L, 84L, 84L, 86L,
86L, 86L, 86L, 86L, 86L, 86L, 86L, 86L, 86L, 85L, 85L, 85L, 84L,
84L, 84L, 84L, 83L, 83L, 83L, 83L, 83L, 82L, 82L, 82L, 82L, 82L,
82L, 82L, 82L, 82L, 82L, 82L, 82L, 82L, 82L, 82L, 82L, 82L, 85L,
84L, 84L, 84L, 84L, 84L, 84L, 84L, 84L, 84L, 84L, 84L, 84L, 84L,
84L, 84L, 84L, 84L, 84L, 83L, 83L, 83L, 83L, 83L, 85L, 85L, 84L,
84L, 84L, 84L, 84L, 84L, 84L, 84L, 84L, 84L, 84L, 84L, 84L, 84L,
86L, 86L, 85L, 85L, 85L, 85L, 85L, 84L, 84L, 84L, 84L, 84L, 84L,
84L, 84L, 84L, 84L, 92L, 90L, 89L, 88L, 88L, 87L, 87L, 87L, 87L,
87L, 87L, 87L, 87L, 90L, 90L, 89L, 89L, 89L, 89L, 89L, 90L, 92L,
92L, 92L, 92L, 92L, 91L, 91L, 91L, 91L, 91L, 90L, 90L, 90L, 90L,
92L, 92L, 92L, 91L, 91L, 91L, 91L, 91L, 91L, 91L, 91L, 91L, 90L,
90L, 91L, 91L, 91L, 91L, 91L, 92L, 92L, 92L, 91L, 90L, 90L, 89L,
89L, 89L, 89L, 88L, 88L, 88L, 88L, 91L, 91L, 92L, 91L, 91L, 91L,
91L, 90L, 89L, 88L, 87L, 87L, 92L, 92L, 92L, 92L, 92L, 92L, 92L,
92L, 92L, 92L, 89L, 89L, 89L, 89L, 89L, 89L, 89L, 89L, 89L, 89L,
85L, 85L, 85L, 85L, 85L, 85L, 86L, 86L, 82L, 83L, 83L, 84L, 84L,
85L, 85L, 86L, 86L, 86L, 74L, 74L, 92L, 92L, 92L, 92L, 92L, 92L,
92L, 92L, 92L, 92L, 90L, 90L, 90L, 90L, 90L, 90L, 90L, 90L, 90L,
90L), Calc.SPM = c(35L, 38L, 37L, 39L, 42L, 42L, 45L, 48L, 46L,
46L, 46L, 44L, 46L, 52L, 50L, 53L, 59L, 67L, 65L, 65L, 41L, 41L,
41L, 40L, 42L, 41L, 41L, 45L, 46L, 47L, 46L, 47L, 47L, 48L, 48L,
49L, 47L, 47L, 46L, 48L, 48L, 51L, 55L, 55L, 65L, 66L, 70L, 72L,
55L, 55L, 60L, 60L, 62L, 68L, 71L, 69L, 77L, 72L, 47L, 54L, 60L,
63L, 68L, 74L, 94L, 94L, 106L, 123L, 120L, 127L, 130L, 36L, 33L,
31L, 34L, 34L, 41L, 55L, 68L, 87L, 114L, 168L, 204L, 226L, 240L,
262L, 42L, 44L, 54L, 58L, 52L, 52L, 51L, 50L, 58L, 68L, 90L,
118L, 156L, 174L, 180L, 187L, 180L, 190L, 189L, 187L, 187L, 185L,
184L, 183L, 192L, 28L, 28L, 28L, 29L, 30L, 31L, 31L, 35L, 40L,
41L, 45L, 48L, 53L, 78L, 169L, 186L, 195L, 25L, 25L, 25L, 27L,
29L, 32L, 32L, 41L, 65L, 70L, 67L, 66L, 69L, 27L, 29L, 74L, 102L,
148L, 141L, 149L, 217L, 24L, 25L, 33L, 88L, 118L, 133L, 170L,
223L, 225L, 27L, 32L, 36L, 41L, 45L, 52L, 66L, 106L, 110L, 106L,
113L, 136L, 149L, 185L, 23L, 23L, 23L, 23L, 24L, 28L, 33L, 40L,
60L, 72L, 76L, 84L, 90L, 92L, 91L, 91L, 90L, 89L, 86L, 85L, 84L,
86L, 15L, 14L, 15L, 14L, 20L, 29L, 32L, 34L, 34L, 37L, 45L, 14L,
14L, 15L, 16L, 17L, 40L, 47L, 53L, 67L, 70L, 85L, 100L, 11L,
11L, 11L, 12L, 12L, 12L, 11L, 11L, 11L, 11L, 12L, 12L, 12L, 12L,
13L, 14L, 16L, 15L, 15L, 15L, 15L, 16L, 16L, 16L, 17L, 18L, 19L,
18L, 20L, 22L, 23L, 24L, 27L, 30L, 28L, 26L, 25L, 24L, 25L, 13L,
14L, 16L, 16L, 17L, 17L, 19L, 20L, 21L, 21L, 21L, 22L, 23L, 23L,
23L, 23L, 21L, 20L, 23L, 22L, 25L, 36L, 39L, 41L, 30L, 34L, 40L,
47L, 53L, 56L, 62L, 64L, 67L, 70L, 88L, 93L, 87L, 89L, 98L, 109L,
17L, 19L, 19L, 21L, 22L, 23L, 28L, 38L, 50L, 63L, 70L, 100L,
118L, 117L, 128L, 135L, 124L, 22L, 19L, 18L, 26L, 42L, 51L, 63L,
65L, 70L, 68L, 70L, 79L, 92L, 31L, 31L, 30L, 31L, 35L, 38L, 42L,
44L, 47L, 45L, 48L, 50L, 51L, 50L, 22L, 23L, 23L, 23L, 31L, 54L,
58L, 56L, 25L, 25L, 25L, 27L, 27L, 25L, 24L, 26L, 30L, 34L, 23L,
23L, 23L, 24L, 24L, 22L, 21L, 20L, 20L, 20L, 21L, 24L, 23L, 25L,
26L, 26L, 26L, 28L, 31L, 36L, 34L, 36L, 34L, 24L, 26L, 28L, 28L,
32L, 32L, 32L, 32L, 31L, 32L, 34L, 37L, 27L, 27L, 29L, 29L, 27L,
27L, 27L, 25L, 25L, 23L, 35L, 35L, 35L, 35L, 39L, 40L, 40L, 43L,
45L, 43L, 67L, 72L, 75L, 82L, 96L, 137L, 142L, 105L, 245L, 264L,
267L, 279L, 248L, 224L, 180L, 137L, 104L, 98L, 293L, 294L, 33L,
35L, 36L, 36L, 35L, 34L, 38L, 38L, 38L, 39L, 27L, 27L, 27L, 28L,
28L, 28L, 28L, 28L, 28L, 29L), Salinity = c(0.06, 0.06, 0.06,
0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.08, 0.08, 0.08, 0.08,
0.08, 0.08, 0.07, 0.07, 0.07, 0.07, 0.08, 0.08, 0.08, 0.08, 0.08,
0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08,
0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.16,
0.16, 0.66, 0.65, 0.66, 0.66, 0.66, 0.66, 0.66, 0.65, 0.65, 0.65,
2.97, 3.12, 3.15, 3.16, 3.17, 3.17, 3.16, 3.16, 3.2, 3.23, 3.23,
3.24, 3.24, 3.86, 4.2, 4.57, 4.68, 4.7, 5, 5.26, 5.5, 5.84, 6.05,
6.12, 6.13, 6.12, 6.12, 6.12, 6.01, 6.23, 6.78, 7.03, 7.16, 7.25,
7.35, 7.34, 7.74, 8.05, 8.25, 8.38, 8.54, 8.59, 8.59, 8.6, 8.58,
8.61, 8.61, 8.63, 8.63, 8.64, 8.63, 8.64, 8.64, 6.87, 6.88, 6.93,
7.37, 7.67, 7.89, 8.09, 8.34, 8.5, 8.54, 8.57, 8.67, 8.81, 9.28,
10.01, 10.07, 10.09, 9.45, 9.5, 9.53, 9.74, 9.92, 10.11, 10.23,
10.94, 11.77, 11.87, 11.79, 11.77, 11.85, 13.1, 13.71, 14.52,
14.63, 14.98, 15.06, 15.06, 15.05, 16.77, 17.64, 18.82, 20.03,
20.27, 20.33, 20.48, 20.56, 20.57, 20.6, 21.19, 21.56, 21.66,
21.73, 21.78, 21.83, 21.88, 21.87, 21.87, 21.88, 21.89, 21.89,
21.89, 20.12, 20.13, 20.23, 20.31, 20.65, 21.24, 21.62, 21.87,
22.12, 22.18, 22.24, 22.34, 22.45, 22.53, 22.55, 22.53, 22.53,
22.52, 22.56, 22.57, 22.57, 22.56, 23.69, 25.05, 25.27, 25.53,
26.04, 26.32, 26.36, 26.38, 26.41, 26.46, 26.46, 25.11, 25.72,
25.97, 26.19, 26.59, 26.97, 27.05, 27.09, 27.15, 27.15, 27.22,
27.22, 27.36, 27.43, 27.48, 27.44, 27.33, 27.26, 27.27, 27.33,
27.37, 27.57, 27.68, 27.72, 27.79, 28.01, 28.19, 28.38, 28.47,
28.48, 28.48, 28.57, 28.66, 28.68, 28.8, 28.85, 28.92, 28.93,
28.95, 28.95, 28.95, 28.93, 28.93, 28.93, 28.91, 28.9, 28.91,
28.91, 28.92, 28.92, 28.92, 26.77, 26.95, 27.12, 27.26, 27.35,
27.33, 27.39, 27.41, 27.44, 27.46, 27.46, 27.47, 27.51, 27.58,
27.61, 27.62, 27.66, 27.71, 27.82, 27.73, 27.87, 27.94, 27.94,
27.94, 26.28, 26.32, 26.42, 26.48, 26.55, 26.59, 26.62, 26.62,
26.64, 26.65, 26.65, 26.65, 26.66, 26.66, 26.65, 26.65, 25.74,
25.9, 25.91, 26.16, 26.23, 26.25, 26.37, 26.45, 26.48, 26.49,
26.5, 26.52, 26.53, 26.53, 26.53, 26.53, 26.53, 24.72, 25, 25.13,
25.3, 25.43, 25.46, 25.49, 25.49, 25.5, 25.49, 25.49, 25.5, 25.5,
25.36, 25.36, 25.36, 25.36, 25.35, 25.35, 25.34, 25.34, 24.45,
24.45, 24.45, 24.45, 24.44, 24.44, 23.78, 23.78, 23.78, 23.78,
23.8, 23.81, 23.81, 23.81, 23.56, 23.56, 23.56, 23.58, 23.63,
23.68, 23.72, 23.73, 23.74, 23.74, 23.31, 23.31, 23.31, 23.33,
23.37, 23.47, 23.51, 23.58, 23.61, 23.61, 23.66, 23.74, 23.12,
23.16, 23.22, 23.26, 23.27, 23.27, 23.29, 23.33, 23.36, 23.38,
23.39, 23.05, 23.05, 23.06, 23.07, 23.08, 23.08, 23.09, 23.1,
23.12, 23.18, 23.25, 23.27, 22.63, 22.63, 22.7, 22.87, 22.89,
22.9, 22.93, 22.95, 22.98, 23.01, 22.33, 22.47, 22.51, 22.55,
22.58, 22.6, 22.62, 22.64, 22.68, 22.72, 21.29, 21.67, 21.67,
21.66, 21.68, 21.74, 21.9, 22.15, 20.73, 20.83, 20.91, 21.02,
21.1, 21.25, 21.39, 21.5, 21.68, 21.83, 20.46, 20.51, 0.06, 0.06,
0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06,
0.06, 0.06, 0.06, 0.06, 0.06, 0.06, 0.06), Temperature = c(19.14,
19.12, 19.11, 19.09, 19.08, 19.08, 19.06, 19.05, 19.06, 19.06,
19.1, 19.11, 19.09, 19.07, 19.07, 19.06, 19.06, 19.05, 19.05,
19.05, 19.32, 19.32, 19.33, 19.32, 19.32, 19.32, 19.32, 19.31,
19.3, 19.3, 19.3, 19.3, 19.3, 19.3, 19.3, 19.29, 19.71, 19.71,
19.72, 19.7, 19.7, 19.68, 19.65, 19.66, 19.62, 19.62, 19.62,
19.62, 19.78, 19.79, 19.76, 19.76, 19.74, 19.72, 19.72, 19.72,
19.71, 19.71, 19.63, 19.54, 19.5, 19.49, 19.48, 19.45, 19.39,
19.39, 19.35, 19.32, 19.33, 19.31, 19.3, 19.47, 19.21, 18.91,
18.86, 18.86, 18.81, 18.76, 18.72, 18.67, 18.64, 18.63, 18.63,
18.63, 18.63, 18.63, 18.93, 18.85, 18.7, 18.65, 18.64, 18.63,
18.62, 18.62, 18.56, 18.51, 18.48, 18.45, 18.42, 18.41, 18.41,
18.41, 18.41, 18.4, 18.41, 18.41, 18.41, 18.41, 18.41, 18.41,
18.41, 19.24, 19.21, 19.09, 18.62, 18.56, 18.5, 18.47, 18.45,
18.43, 18.44, 18.44, 18.44, 18.44, 18.41, 18.34, 18.34, 18.33,
18.72, 18.66, 18.65, 18.5, 18.39, 18.3, 18.28, 18.21, 18.13,
18.12, 18.13, 18.13, 18.12, 19.18, 18.47, 18.05, 18.02, 17.96,
17.95, 17.95, 17.95, 18.36, 17.55, 17.21, 16.85, 16.78, 16.76,
16.71, 16.69, 16.69, 16.84, 16.61, 16.51, 16.45, 16.42, 16.39,
16.37, 16.34, 16.34, 16.34, 16.34, 16.33, 16.33, 16.32, 17.11,
17.05, 16.88, 16.81, 16.69, 16.52, 16.4, 16.31, 16.21, 16.19,
16.17, 16.14, 16.12, 16.1, 16.1, 16.1, 16.1, 16.11, 16.11, 16.11,
16.11, 16.12, 16.32, 15.69, 15.54, 15.46, 15.2, 15.05, 15.02,
15.01, 14.99, 14.96, 14.96, 15.28, 15.16, 15.09, 15.04, 14.93,
14.77, 14.74, 14.72, 14.69, 14.69, 14.66, 14.65, 14.77, 14.74,
14.71, 14.73, 14.8, 14.83, 14.83, 14.8, 14.78, 14.66, 14.59,
14.57, 14.52, 14.39, 14.27, 14.15, 14.09, 14.09, 14.09, 14.03,
13.97, 13.96, 13.89, 13.86, 13.8, 13.79, 13.77, 13.77, 13.77,
13.78, 13.78, 13.78, 13.78, 13.78, 13.78, 13.78, 13.77, 13.77,
13.77, 14.97, 14.87, 14.77, 14.7, 14.65, 14.67, 14.65, 14.64,
14.63, 14.62, 14.62, 14.61, 14.59, 14.54, 14.52, 14.5, 14.49,
14.47, 14.4, 14.45, 14.38, 14.34, 14.34, 14.34, 15.6, 15.58,
15.53, 15.49, 15.46, 15.44, 15.43, 15.43, 15.41, 15.39, 15.38,
15.38, 15.38, 15.38, 15.39, 15.4, 15.69, 15.63, 15.63, 15.58,
15.58, 15.59, 15.57, 15.53, 15.5, 15.49, 15.48, 15.46, 15.45,
15.45, 15.44, 15.44, 15.45, 17.95, 17.59, 17.42, 17.15, 16.93,
16.87, 16.83, 16.81, 16.8, 16.81, 16.8, 16.79, 16.79, 17.2, 17.2,
17.2, 17.2, 17.21, 17.21, 17.22, 17.22, 18.16, 18.16, 18.16,
18.16, 18.16, 18.16, 18.88, 18.88, 18.88, 18.88, 18.87, 18.86,
18.86, 18.86, 19.34, 19.35, 19.34, 19.33, 19.26, 19.13, 19, 18.97,
18.96, 18.96, 19.76, 19.76, 19.77, 19.75, 19.68, 19.46, 19.37,
19.2, 19.14, 19.12, 19.03, 18.88, 20.13, 20.1, 19.98, 19.88,
19.86, 19.85, 19.81, 19.77, 19.73, 19.7, 19.68, 20.28, 20.27,
20.26, 20.25, 20.24, 20.23, 20.21, 20.18, 20.13, 19.96, 19.78,
19.76, 20.48, 20.48, 20.46, 20.31, 20.27, 20.25, 20.23, 20.2,
20.19, 20.17, 20.38, 20.36, 20.37, 20.36, 20.33, 20.31, 20.31,
20.31, 20.29, 20.26, 20.51, 20.43, 20.39, 20.37, 20.34, 20.22,
20.06, 19.91, 20.53, 20.49, 20.48, 20.46, 20.47, 20.48, 20.48,
20.48, 20.49, 20.48, 19.47, 19.43, 19.11, 19.1, 19.08, 19.09,
19.09, 19.09, 19.09, 19.1, 19.1, 19.11, 18.22, 18.22, 18.23,
18.22, 18.2, 18.2, 18.2, 18.2, 18.2, 18.2)), class = "data.frame", row.names = c(NA,
-453L))
##Setting up data
example.data$Date<-'06/10/2005'
example.data$Date<-as.Date(example.data$Date,"%m/%d/%Y")
d_date<-example.data[example.data$Date=='2005-06-10',]
d_date<-drop_na(d_date,c(Calc.Chl,DO,Calc.SPM,Salinity,Temperature))
d_date$logDepth<-log10(d_date$Depth)
##add a line, if minimum depth #station > 1, copy minimum as all depths between 1 and min
#Interpolations
interp.chl <- interp(d_date$Distance.from.36, d_date$logDepth, d_date$Calc.Chl, nx = 1000, ny = 800,yo=seq(0,max(d_date$logDepth), length = 800))
interp.df.chl <- interp.chl %>% interp2xyz() %>% as.data.frame()
names(interp.df.chl) <- c("x", "y", "Chl")
interp.do <- interp(d_date$Distance.from.36, d_date$logDepth, d_date$DO, nx = 1000, ny = 800,yo=seq(0,max(d_date$logDepth), length = 800))
interp.df.do <- interp.do %>% interp2xyz() %>% as.data.frame()
names(interp.df.do) <- c("x", "y", "Oxy")
interp.spm <- interp(d_date$Distance.from.36, d_date$logDepth, d_date$Calc.SPM, nx = 1000, ny = 800,yo=seq(0,max(d_date$logDepth), length = 800))
interp.df.spm <- interp.spm %>% interp2xyz() %>% as.data.frame()
names(interp.df.spm) <- c("x", "y", "SPM")
interp.sal <- interp(d_date$Distance.from.36, d_date$logDepth, d_date$Salinity, nx = 1000, ny = 800,yo=seq(0,max(d_date$logDepth), length = 800))
interp.df.sal <- interp.sal %>% interp2xyz() %>% as.data.frame()
names(interp.df.sal) <- c("x", "y", "Sal")
interp.temp <- interp(d_date$Distance.from.36, d_date$logDepth, d_date$Temperature, nx = 1000, ny = 800,yo=seq(0,max(d_date$logDepth), length = 800))
interp.df.temp <- interp.temp %>% interp2xyz() %>% as.data.frame()
names(interp.df.temp) <- c("x", "y", "Temp")
For context, our data is organized by date/station/depth, where each date is sampled at many locations (stations), at depths in 1m increments. If we drop surface data, there is no 1m depth, and the first depth is 2. Here is a snip of data of two stations within one date that one minimum depth is 1m and the second is 2m.
TIA!
I am trying to carry out linear discriminant analysis and plot the results graphically:
aircraft = read_csv(file = "aircraft.csv") %>%
mutate( Period = factor( Period ))
lda.0 = lda( Period ~ Power + Span + Length + Weight + Speed + Range, data = aircraft )
plot( lda.0 )
Using my full dataset, I get the following graph:
As you can see, it is difficult to see what is going on here. I want to plot this in a more informative way.
I was thinking of using ggplot with something like this:
ggplot( lda.0, aes( ) ) +
geom_density_2d( ) +
geom_point( aes( colour = ), alpha = 0.5 ) +
theme( legend.position = "bottom") +
theme( legend.position = "bottom") + ggtitle("Contour Plot") + theme(plot.title=element_text(hjust=0.5))
So that I get a graph like this:
Or a graph like this:
Or a graph like this:
How do I accomplish this (as I said, I would like to use something more flexible like ggplot)?
However, the full dataset is too large to include in this post, so I have included a smaller version of the dataset:
structure(list(Year = c(14L, 14L, 14L, 15L, 15L, 15L, 15L, 16L,
16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 17L, 17L,
17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L,
18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 19L, 19L, 20L, 20L, 20L,
20L, 21L, 21L, 21L, 22L, 22L, 22L, 22L, 22L, 23L, 23L, 23L, 23L,
23L, 23L, 23L, 23L, 23L, 24L, 24L, 24L, 24L, 24L, 25L, 25L, 25L,
25L, 25L, 25L, 25L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L,
26L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 28L, 28L, 28L, 28L,
28L), Period = c(1L, 3L, 3L, 1L, 2L, 1L, 3L, 2L, 1L, 3L, 2L,
3L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 3L, 1L, 3L, 3L, 2L, 1L, 1L, 1L,
1L, 3L, 2L, 1L, 1L, 3L, 2L, 1L, 2L, 1L, 1L, 2L, 1L, 2L, 1L, 3L,
2L, 3L, 1L, 1L, 2L, 3L, 1L, 3L, 2L, 1L, 2L, 1L, 1L, 1L, 3L, 2L,
2L, 3L, 1L, 3L, 1L, 3L, 2L, 1L, 1L, 2L, 1L, 3L, 1L, 1L, 2L, 2L,
3L, 3L, 1L, 3L, 1L, 2L, 1L, 2L, 1L, 1L, 3L, 1L, 1L, 2L, 3L, 2L,
1L, 2L, 1L, 1L, 1L, 3L, 2L, 1L, 2L), Power = c(82, 82, 223.6,
164, 119, 74.5, 74.5, 279.5, 82, 67, 112, 149, 119, 119, 238.5,
205, 82, 119, 194, 336, 558.9, 287, 388, 164, 194, 194, 186.3,
119, 119, 89.4, 126.7, 149, 119, 536.6, 402, 298, 298, 342.8,
536, 223.6, 521.6, 186.3, 238.5, 287, 335.3, 335.3, 335.3, 335.3,
335.3, 335.3, 357.7, 313, 782.6, 298, 670.6, 223.5, 335.3, 391,
391, 436, 391, 436, 171.4, 350, 298, 223.6, 298, 634, 223.5,
864.4, 760, 503.5, 63.3, 357.7, 812, 335.3, 298, 298, 335.3,
298, 317, 231, 335.3, 432, 918, 745.2, 424.8, 372.6, 782, 626,
544, 335.3, 372.6, 373, 391.2, 864, 894, 179, 74.5, 391.2), Span = c(12.8,
11, 17.9, 14.5, 12.9, 7.5, 11.13, 14.3, 7.8, 11, 11.7, 12.8,
8.5, 13.3, 14.9, 12, 9.4, 15.95, 16.74, 22.2, 23.4, 14.3, 23.72,
11.9, 14.4, 14.4, 9.7, 8, 9.4, 14.55, 9.1, 8.11, 9.5, 20.73,
22.8, 38.4, 14, 26.5, 30.48, 9.7, 15.5, 9.1, 14.17, 10.1, 14.8,
15.62, 14.05, 14.05, 14.8, 15.24, 14, 12.24, 27.2, 8.84, 22.86,
7.7, 9.5, 9.8, 15.93, 15.93, 15.93, 15.93, 13.08, 15.21, 8.94,
9.6, 10.8, 13.72, 8.9, 26.72, 25, 9.6, 8.84, 11.58, 17.3, 12.5,
12.1, 12.09, 9.8, 15.3, 9.08, 17.75, 15.3, 15.15, 27.4, 22, 13.7,
10.3, 22.76, 22.25, 17.25, 11, 12, 9.5, 14.15, 20.4, 20.4, 14.5,
8.84, 11.35), Length = c(7.6, 9, 10.35, 9.8, 7.9, 6.3, 8.28,
9.4, 6.7, 8.3, 8, 8.7, 7.4, 9.6, 8.9, 7.9, 6.2, 10.25, 10.77,
10.9, 12.6, 9.4, 11.86, 9.8, 9.2, 8.9, 8, 6.5, 6.95, 9.83, 7.3,
6.38, 8.5, 13.27, 13.5, 20.85, 9.2, 14.33, 19.16, 6.5, 9.7, 8.1,
9.68, 7.7, 10.8, 11.89, 10.97, 11.28, 9.5, 11.42, 11, 7.3, 18.2,
7.01, 18.08, 6.8, 6.8, 7.1, 11.5, 11.5, 11.5, 11.5, 9.27, 9.78,
6.17, 6.4, 7.32, 10.74, 6.9, 18.97, 15.1, 7.06, 7.17, 9.5, 10.55,
8.38, 8.7, 8.81, 6.7, 9.42, 5.99, 10.27, 10.22, 11, 19.8, 14.63,
11.2, 6.56, 14.88, 13.81, 12.6, 7, 7.5, 7.2, 9.91, 14.8, 15,
9.8, 7.17, 8.94), Weight = c(1070, 830, 2200, 1946, 1190, 653,
930, 1575, 676, 920, 1353, 1550, 888, 1275, 1537, 1292, 611,
1350, 1700, 3312, 4920, 1510, 3625, 900, 1665, 1640, 1081, 625,
932, 1378, 886, 902, 1070, 5670, 3636, 12925, 2107, 4770, 6060,
1192, 1900, 1050, 2155, 1379, 2858, 3380, 2290, 2290, 2347, 3308,
2630, 1333, 10000, 1351, 6250, 885, 1531, 1438, 3820, 3820, 3820,
3820, 1905, 2646, 1151, 1266, 1575, 2383, 860, 7983, 6200, 1484,
567, 1867, 4350, 1935, 1823, 2253, 1487, 2220, 1244, 2700, 2280,
3652, 8165, 5500, 3568, 1414, 5875, 5460, 4310, 1500, 1795, 1628,
2449, 6900, 6900, 1900, 567, 2102), Speed = c(105L, 145L, 135L,
138L, 140L, 177L, 113L, 230L, 175L, 106L, 140L, 170L, 175L, 157L,
183L, 201L, 209L, 145L, 120L, 135L, 152L, 176L, 140L, 190L, 175L,
175L, 205L, 196L, 165L, 146L, 175L, 222L, 159L, 166L, 158L, 146L,
185L, 120L, 157L, 226L, 205L, 230L, 161L, 251L, 171L, 206L, 171L,
171L, 235L, 161L, 145L, 245L, 183L, 214L, 180L, 220L, 237L, 254L,
169L, 169L, 169L, 169L, 153L, 183L, 261L, 245L, 235L, 200L, 246L,
174L, 180L, 319L, 146L, 251L, 230L, 290L, 230L, 233L, 250L, 255L,
233L, 175L, 230L, 180L, 145L, 185L, 196L, 298L, 183L, 198L, 195L,
300L, 270L, 297L, 225L, 212L, 195L, 197L, 146L, 296L), Range = c(400L,
402L, 500L, 500L, 400L, 350L, 402L, 700L, 525L, 300L, 560L, 550L,
250L, 450L, 700L, 600L, 175L, 450L, 450L, 450L, 600L, 800L, 500L,
600L, 600L, 600L, 600L, 400L, 250L, 400L, 350L, 547L, 450L, 1770L,
800L, 2365L, 925L, 400L, 1205L, 580L, 600L, 600L, 684L, 402L,
563L, 644L, 885L, 885L, 800L, 440L, 557L, 750L, 3600L, 500L,
805L, 330L, 600L, 628L, 1640L, 1640L, 1640L, 1640L, 604L, 1046L,
644L, 500L, 600L, 1046L, 550L, 1585L, 650L, 917L, 515L, 805L,
750L, 1110L, 772L, 1127L, 500L, 850L, 523L, 850L, 900L, 700L,
668L, 700L, 1706L, 600L, 1385L, 1000L, 902L, 600L, 500L, 450L,
579L, 1125L, 1300L, 660L, 515L, 756L)), row.names = c(NA, 100L
), class = "data.frame")
EDIT:
Is this what you want?
lda.0.val = predict(lda.0)$x
df = data.frame(
LD1 = lda.0.val[,1],
LD2 = lda.0.val[,2],
Period = aircraft$Period)
ggplot(df, aes(x=LD1, y=LD2)) +
geom_density_2d() + geom_point(aes(color=Period))
Output:
I am trying to add a smooth curve to my ggplot histogram plot using geom_density():
ggplot(aircraft, aes(log10(Power))) + geom_histogram() + geom_density()
However, as you can see from the small curve at the bottom of the graph, it isn't working as I wanted:
This is an example of the type of smooth curve I want:
How do I add this smooth curve to my histogram?
My data is too large to add here, so here is a sample of it:
structure(list(Year = c(14L, 14L, 14L, 15L, 15L, 15L, 15L, 16L,
16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 17L, 17L,
17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L,
18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 19L, 19L, 20L, 20L, 20L,
20L, 21L, 21L, 21L, 22L, 22L, 22L, 22L, 22L, 23L, 23L, 23L, 23L,
23L, 23L, 23L, 23L, 23L, 24L, 24L, 24L, 24L, 24L, 25L, 25L, 25L,
25L, 25L, 25L, 25L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L,
26L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 28L, 28L, 28L, 28L,
28L), Period = c(1L, 3L, 3L, 1L, 2L, 1L, 3L, 2L, 1L, 3L, 2L,
3L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 3L, 1L, 3L, 3L, 2L, 1L, 1L, 1L,
1L, 3L, 2L, 1L, 1L, 3L, 2L, 1L, 2L, 1L, 1L, 2L, 1L, 2L, 1L, 3L,
2L, 3L, 1L, 1L, 2L, 3L, 1L, 3L, 2L, 1L, 2L, 1L, 1L, 1L, 3L, 2L,
2L, 3L, 1L, 3L, 1L, 3L, 2L, 1L, 1L, 2L, 1L, 3L, 1L, 1L, 2L, 2L,
3L, 3L, 1L, 3L, 1L, 2L, 1L, 2L, 1L, 1L, 3L, 1L, 1L, 2L, 3L, 2L,
1L, 2L, 1L, 1L, 1L, 3L, 2L, 1L, 2L), Power = c(82, 82, 223.6,
164, 119, 74.5, 74.5, 279.5, 82, 67, 112, 149, 119, 119, 238.5,
205, 82, 119, 194, 336, 558.9, 287, 388, 164, 194, 194, 186.3,
119, 119, 89.4, 126.7, 149, 119, 536.6, 402, 298, 298, 342.8,
536, 223.6, 521.6, 186.3, 238.5, 287, 335.3, 335.3, 335.3, 335.3,
335.3, 335.3, 357.7, 313, 782.6, 298, 670.6, 223.5, 335.3, 391,
391, 436, 391, 436, 171.4, 350, 298, 223.6, 298, 634, 223.5,
864.4, 760, 503.5, 63.3, 357.7, 812, 335.3, 298, 298, 335.3,
298, 317, 231, 335.3, 432, 918, 745.2, 424.8, 372.6, 782, 626,
544, 335.3, 372.6, 373, 391.2, 864, 894, 179, 74.5, 391.2), Span = c(12.8,
11, 17.9, 14.5, 12.9, 7.5, 11.13, 14.3, 7.8, 11, 11.7, 12.8,
8.5, 13.3, 14.9, 12, 9.4, 15.95, 16.74, 22.2, 23.4, 14.3, 23.72,
11.9, 14.4, 14.4, 9.7, 8, 9.4, 14.55, 9.1, 8.11, 9.5, 20.73,
22.8, 38.4, 14, 26.5, 30.48, 9.7, 15.5, 9.1, 14.17, 10.1, 14.8,
15.62, 14.05, 14.05, 14.8, 15.24, 14, 12.24, 27.2, 8.84, 22.86,
7.7, 9.5, 9.8, 15.93, 15.93, 15.93, 15.93, 13.08, 15.21, 8.94,
9.6, 10.8, 13.72, 8.9, 26.72, 25, 9.6, 8.84, 11.58, 17.3, 12.5,
12.1, 12.09, 9.8, 15.3, 9.08, 17.75, 15.3, 15.15, 27.4, 22, 13.7,
10.3, 22.76, 22.25, 17.25, 11, 12, 9.5, 14.15, 20.4, 20.4, 14.5,
8.84, 11.35), Length = c(7.6, 9, 10.35, 9.8, 7.9, 6.3, 8.28,
9.4, 6.7, 8.3, 8, 8.7, 7.4, 9.6, 8.9, 7.9, 6.2, 10.25, 10.77,
10.9, 12.6, 9.4, 11.86, 9.8, 9.2, 8.9, 8, 6.5, 6.95, 9.83, 7.3,
6.38, 8.5, 13.27, 13.5, 20.85, 9.2, 14.33, 19.16, 6.5, 9.7, 8.1,
9.68, 7.7, 10.8, 11.89, 10.97, 11.28, 9.5, 11.42, 11, 7.3, 18.2,
7.01, 18.08, 6.8, 6.8, 7.1, 11.5, 11.5, 11.5, 11.5, 9.27, 9.78,
6.17, 6.4, 7.32, 10.74, 6.9, 18.97, 15.1, 7.06, 7.17, 9.5, 10.55,
8.38, 8.7, 8.81, 6.7, 9.42, 5.99, 10.27, 10.22, 11, 19.8, 14.63,
11.2, 6.56, 14.88, 13.81, 12.6, 7, 7.5, 7.2, 9.91, 14.8, 15,
9.8, 7.17, 8.94), Weight = c(1070, 830, 2200, 1946, 1190, 653,
930, 1575, 676, 920, 1353, 1550, 888, 1275, 1537, 1292, 611,
1350, 1700, 3312, 4920, 1510, 3625, 900, 1665, 1640, 1081, 625,
932, 1378, 886, 902, 1070, 5670, 3636, 12925, 2107, 4770, 6060,
1192, 1900, 1050, 2155, 1379, 2858, 3380, 2290, 2290, 2347, 3308,
2630, 1333, 10000, 1351, 6250, 885, 1531, 1438, 3820, 3820, 3820,
3820, 1905, 2646, 1151, 1266, 1575, 2383, 860, 7983, 6200, 1484,
567, 1867, 4350, 1935, 1823, 2253, 1487, 2220, 1244, 2700, 2280,
3652, 8165, 5500, 3568, 1414, 5875, 5460, 4310, 1500, 1795, 1628,
2449, 6900, 6900, 1900, 567, 2102), Speed = c(105L, 145L, 135L,
138L, 140L, 177L, 113L, 230L, 175L, 106L, 140L, 170L, 175L, 157L,
183L, 201L, 209L, 145L, 120L, 135L, 152L, 176L, 140L, 190L, 175L,
175L, 205L, 196L, 165L, 146L, 175L, 222L, 159L, 166L, 158L, 146L,
185L, 120L, 157L, 226L, 205L, 230L, 161L, 251L, 171L, 206L, 171L,
171L, 235L, 161L, 145L, 245L, 183L, 214L, 180L, 220L, 237L, 254L,
169L, 169L, 169L, 169L, 153L, 183L, 261L, 245L, 235L, 200L, 246L,
174L, 180L, 319L, 146L, 251L, 230L, 290L, 230L, 233L, 250L, 255L,
233L, 175L, 230L, 180L, 145L, 185L, 196L, 298L, 183L, 198L, 195L,
300L, 270L, 297L, 225L, 212L, 195L, 197L, 146L, 296L), Range = c(400L,
402L, 500L, 500L, 400L, 350L, 402L, 700L, 525L, 300L, 560L, 550L,
250L, 450L, 700L, 600L, 175L, 450L, 450L, 450L, 600L, 800L, 500L,
600L, 600L, 600L, 600L, 400L, 250L, 400L, 350L, 547L, 450L, 1770L,
800L, 2365L, 925L, 400L, 1205L, 580L, 600L, 600L, 684L, 402L,
563L, 644L, 885L, 885L, 800L, 440L, 557L, 750L, 3600L, 500L,
805L, 330L, 600L, 628L, 1640L, 1640L, 1640L, 1640L, 604L, 1046L,
644L, 500L, 600L, 1046L, 550L, 1585L, 650L, 917L, 515L, 805L,
750L, 1110L, 772L, 1127L, 500L, 850L, 523L, 850L, 900L, 700L,
668L, 700L, 1706L, 600L, 1385L, 1000L, 902L, 600L, 500L, 450L,
579L, 1125L, 1300L, 660L, 515L, 756L)), row.names = c(NA, 100L
), class = "data.frame")
One solution could be to set y = ..density.. in the aes
library(tidyverse)
ggplot(aircraft, aes(x = log10(Power),
y = ..density..)) +
geom_histogram(alpha =0.5) +
geom_density(color = "red",
size = 2)
I am very new to R, so this might be very simple to solve.
I have a data frame composed by several columns representing different variables. I would like to do a multiple correlation, pairing all the variables.
This is my data frame:
df <- structure(list(ATA = c(26.41, 35.89, 42.68, 41.92, 37.43, 32.72,
31.97, 18.59, 38.71, 38.74, 28.61, 21.31, 38.66, 42.82, 46.17,
28.39, 28.17, 39.24, 42.44, 31.56, 41.95, 37.52, 32.15, 51.96,
33.37, 32.8, 31.92, 40.21, 41.71, 32.61, 35.97, 42.44, 37.36,
35.35, 37.08, 41.42, 43.71, 47.29, 31.22, 19.72, 23.74, 38.2,
47.27, 47.47, 40.17, 37, 37.6, 37.5, 34.78, 35.43, 39.32, 42.63,
42.52, 36.37, 36.71, 34.48, 40.06, 47.65, 37.1, 18.52, 36.98,
14.44, 44.46, 26.61, 32.13, 33.11, 33.64, 37.67, 28.07, 15.09,
42.08, 32.47, 38.6, 23.01, 31.02, 27.86, 31.19, 39.48, 39.79,
31.22, 32.6, 40.19, 26.81, 35.29, 32.09, 28.72, 29.98, 30.46,
29.21, 29.34, 35.94, 41.07, 29.53, 41.62, 15.12, 34.79, 19.35,
32.93, 32.13, 25.6, 32.57, 35.48, 33.38, 24.58, 46.79, 31.48,
32.83, 25.45, 18.45, 36.61, 23.52, 36.84, 30.09, 30.26, 34.28,
37.17, 34.94, 20.66, 28.35, 25.22, 36.58, 33.19, 42.34, 34.19,
50.82, 31.01, 42.44, 18.4, 36.38, 34.8, 42.34, 42.42, 20.85,
43.25, 18.55, 44.78, 27.61, 37.62, 19.12, 43.5, 36.18, 40.5,
28.31, 44.67, 42.46, 34.72, 19.09, 23.62, 39.61, 37.61, 31.45,
34, 24.96, 42.34, 28.14, 37.94, 37.12, 39.27, 38.09, 49.29, 29.82,
30.74, 38.69, 40.52, 42.9, 44.79, 35.95, 38.26, 27.76, 35.3,
52.03, 33.72, 32.28, 39.32, 39.08, 37.47, 18.06, 22.61, 40.1,
32.5, 22.51, 39.48, 37.27, 33.2, 27.54, 23.09, 23.94, 34.22,
40.57, 28.11, 33.13, 20.33, 28.99, 31.28, 32.18, 33.11, 36.15,
39.52, 37.24, 35.18, 37.5, 38.79, 40.19, 42.63, 37.34, 44.08,
43.81, 36.88, 32.42, 38.88, 27.69, 33.44, 34.63, 37.6, 41.43,
40.32, 36.36, 38.63, 36.33, 32.08, 40.8, 41.77, 30.32, 38.79,
26.26, 22.26, 23.11, 37.9, 15.79, 29.88, 29.64, 39.54, 42.24,
21.8, 32.42, 37.99, 37.21, 36.11, 51.71, 23.49, 40.02, 42.68,
44.13, 35.01, 30.32, 47.3, 24.25, 44.32, 39.45, 26.52, 34.74,
41.14, 37.52, 44.21, 45.34, 47.01, 16.99, 29.67, 16.31, 48.67,
21.35, 41.62, 23.61, 48.6, 21.39, 28.38, 26.78, 25.09, 15.94,
16.39, 28.34, 34.32, 46.46, 42.49, 19.86, 26.92, 25.58, 38.06,
30.57, 51.33, 41.82, 17.43, 28.46, 29.97, 34.76, 27.46, 41.98,
26.29, 26.8, 17.24, 39.7, 37.8, 51.78, 40.45, 30.52, 35, 44.15,
21.42, 52.15, 33.27, 35.7, 25.26, 55.08, 21.87, 28.26, 42.21,
43.25, 40.81, 32.57, 38.46, 33.39, 41.59, 35.56, 31.49, 31.42,
36.27, 20.52, 35.03, 29.84, 32.56, 29.62, 53.26, 36.27, 33.21,
54.44, 54.88, 36.02, 33.78, 45.53, 41.4, 31.9, 45.61, 51.93,
55.99, 26.88, 43.45, 53.82, 38.02, 44.76, 43.92, 50.04, 41.6,
47.76, 22.58, 17.62, 50.74, 45.2, 56.84, 48.09, 31.51, 50.76,
17.82, 43.37, 24.66, 50.32, 19.46, 23.32, 42.51, 44.18, 40.78,
21.15, 20.74, 22.73, 15.18, 39.2, 48.03, 39.41, 38.52, 43.21,
25.51, 42.72, 37.73, 20.88, 18.94, 32.94, 27.61, 21.83, 34.76,
23.52, 36.57, 28.07, 30.09, 38.58, 42.76, 43.87, 37.67, 41.2,
39.13, 39.19, 39.52, 14.91, 38.47, 32.61, 28.45, 41.2, 44.24),
AEA = c(28.25, 27.96, 38.15, 48.97, 31.64, 29.25, 23.3, 15.62,
39.07, 47.96, 38.13, 21.47, 36.5, 30.81, 41.46, 33.89, 31.93,
29.46, 44.67, 31.07, 40.27, 36.98, 45.35, 51.1, 41.07, 24.96,
23.94, 28.9, 46.36, 29.94, 44.49, 44.48, 35.4, 49.12, 29.13,
41.23, 48.22, 48.3, 21.72, 19.72, 23.74, 44.49, 36.43, 38.2,
36.14, 38.49, 33.69, 30.61, 30.18, 43.78, 45.69, 47.72, 46.59,
39.86, 24.77, 35.97, 43.05, 25.13, 40.77, 22.64, 38.11, 11.71,
37.02, 39.92, 30.15, 33.38, 36.08, 37.06, 34.96, 15.86, 36.99,
22.72, 29.91, 23.01, 31.17, 35.27, 39.98, 41.74, 45.05, 31.55,
27.65, 45.23, 43.88, 46.64, 36.9, 36.87, 29.13, 31.93, 37.39,
24.07, 38.94, 50.03, 35.78, 47.77, 16, 39.52, 25.2, 44.55,
43.82, 25.42, 54.65, 34.93, 19.9, 29.17, 46.79, 36.55, 37.91,
19.16, 14.23, 32.48, 24.98, 45.98, 32.17, 30.17, 40.18, 39.61,
36.11, 20.66, 30.75, 25.05, 39.26, 37.65, 38.79, 35.25, 34.26,
29.85, 31.36, 17.17, 18.59, 29.44, 38.56, 44.02, 18.73, 42.73,
17.76, 36.98, 33.43, 34.97, 23.2, 50.31, 39.86, 12.49, 24.53,
56.6, 45.33, 36.07, 18.56, 23.38, 39.13, 41.67, 35.5, 36.98,
55.22, 42.89, 23.67, 39.66, 38.51, 48.93, 37.39, 42.21, 42.79,
35.73, 45.62, 34.08, 43.77, 43.31, 38.04, 36.98, 31.03, 20.58,
55.91, 34.5, 30.83, 35.85, 46.1, 43.7, 20.23, 30.74, 41.79,
35.74, 42.58, 45.04, 48.57, 33.26, 28.62, 31.72, 23.09, 44.55,
40, 30.03, 43.86, 22.84, 44.11, 42.82, 33.19, 31.09, 40,
42.11, 39.21, 36.5, 49.4, 48.06, 36.55, 42.71, 40, 38.1,
44.56, 27.05, 29.27, 40.55, 29.64, 35.7, 28.22, 17.69, 44.76,
33.69, 37.44, 38.85, 26.6, 39.13, 55.28, 41.77, 47.28, 24.88,
40.17, 26.31, 38.32, 47.15, 23.99, 29.04, 31.16, 27.36, 45.95,
42.9, 32.43, 33.89, 34.34, 33.84, 47.87, 23.98, 46.92, 31.16,
40.93, 41.33, 32.44, 51.93, 34.46, 36.2, 45.97, 32.11, 44.74,
39.76, 47.28, 39.87, 40.62, 50.47, 18.03, 19.45, 15.67, 29.17,
18.17, 39.54, 15.11, 31.63, 22.38, 36.62, 27.07, 38.75, 20.85,
24.17, 16.9, 21.79, 47.99, 29.62, 19.86, 12.29, 28.67, 35.9,
32.96, 31.3, 42.96, 11.21, 26.01, 27.08, 18.29, 16.03, 39.38,
20.72, 42.86, 25.34, 46.5, 11.99, 47.96, 48.16, 25.68, 33.31,
47.68, 38.28, 50.02, 28.6, 41.95, 27.53, 48.04, 34.85, 33.36,
26.26, 51.42, 37.95, 49.2, 47.5, 23.21, 30.26, 43.56, 41.43,
31.58, 28.61, 16.5, 42.09, 18.55, 17.79, 25.78, 24.69, 17.86,
43.71, 34.4, 22.86, 35.76, 30.66, 27.75, 22.76, 44.72, 33.96,
39.91, 43.56, 21.23, 40.58, 57.96, 45.92, 26.55, 39.85, 38.77,
28.42, 27.49, 21.97, 14.93, 44.06, 44.78, 52.96, 33.52, 37.9,
26.02, 19.51, 33.05, 11.14, 41.1, 20.67, 24.34, 43.39, 30.87,
22.9, 30.64, 18.17, 18.15, 21.13, 26.91, 50.79, 30.62, 37.64,
27.23, 21.92, 45.19, 29.66, 26.27, 29.15, 20.93, 23.27, 17.2,
46.23, 18.1, 33.77, 26.81, 21.5, 35.66, 31.15, 32.89, 40.14,
43.64, 39.79, 45.23, 36.39, 13.33, 30.48, 22.8, 17.36, 25.64,
32.28), TL = c(1611.73, 2000.03, 1708.56, 1482.78, 1930.17,
1517.96, 1645.54, 875.36, 363.9, 1211.11, 707.75, 126, 1896.33,
1201.09, 1666.03, 399.99, 899.19, 1440.9, 1220.85, 441.89,
1301.19, 411.25, 1058.35, 690.71, 468.28, 493.29, 696.64,
720.94, 937.48, 873.6, 1161.28, 1183.29, 1187.31, 1383.79,
1282.36, 1401.17, 1664.07, 1302.93, 933.67, 87.4, 93.95,
1195.63, 1438.75, 1319.66, 1418.64, 1327.36, 1144.91, 948.1,
1321.69, 762.5, 997.04, 1440.75, 1408.02, 866.92, 1246.34,
598.59, 1063.82, 1085.85, 1207.25, 134.17, 1140.67, 985.6,
322.6, 1465.07, 967.79, 1599.73, 952, 1299.05, 1393.75, 91.43,
990.4, 578.34, 1172.86, 54.6, 91.27, 303.89, 572.89, 451.17,
789.86, 486.99, 724.69, 945.37, 770.01, 781.5, 854.24, 757.08,
800.99, 1151.25, 878.57, 993.9, 1321.97, 1026.26, 1940.87,
1102.77, 119.1, 1022.64, 387.96, 733.32, 733.32, 1763.76,
1513.12, 1817.78, 1135.1, 831.09, 34.03, 1369.28, 917.96,
908.13, 683.13, 1166.54, 807.42, 1153.25, 1565.59, 150.23,
680.17, 1928.68, 1016.73, 66.74, 1112.68, 197.12, 1074.66,
1066.72, 1492.29, 1734.69, 1637.43, 989.48, 1599.23, 579.92,
719.32, 587.93, 1138.26, 1221.17, 155.19, 1725.77, 588.6,
1312.38, 313.34, 1613.8, 338.36, 1151.78, 1049.66, 581.26,
620.8, 1100.6, 903.21, 927.57, 546.59, 592.5, 1515.52, 1529.04,
989.13, 1136.83, 820.87, 1473.18, 501.83, 1297.74, 1046.32,
1561.67, 1189.51, 1509.71, 1950.75, 889.54, 1626.39, 963.38,
1104.73, 1347.17, 1233.09, 1157.94, 244.12, 844.23, 1090.23,
1261.21, 1398.66, 1598.67, 1103.24, 1434.42, 1490.93, 1162.7,
1148.45, 1617.38, 1756.51, 1556.14, 1596.56, 389.17, 962.41,
389.78, 331.44, 1434.05, 1132.93, 1162.65, 739.07, 839.96,
1356.59, 1242.56, 1274.23, 1185.76, 1553.95, 762.44, 704.39,
864.76, 751.27, 934.28, 676.79, 1327.19, 1216.19, 1323.44,
1263.23, 1029, 1365.65, 1311.42, 754.7, 1032.19, 785.28,
1059.54, 949.51, 1104.21, 1472.86, 1380.74, 488.81, 586.57,
812.65, 43.01, 971.71, 1273, 1386.87, 471.91, 1279.95, 1419.04,
746.12, 603.88, 599.53, 1193.19, 772.09, 656.75, 1269.64,
1592.46, 224.31, 1565.19, 314.17, 732.08, 797.02, 650.48,
979.58, 981.88, 1021.67, 1033.49, 615.97, 879.24, 1202.83,
891.77, 752.86, 1100.06, 1435.95, 1490.92, 1700.68, 988.49,
306.85, 1598.08, 2026.11, 1797.46, 1713.56, 1931.49, 1454.85,
1738.81, 606.43, 444.09, 205.4, 169.68, 257.38, 231.88, 400.34,
815.09, 307, 647.04, 35.05, 367.68, 311.54, 751.33, 1009.03,
935.37, 157.38, 308.69, 709.07, 388.39, 449.79, 376.5, 947.29,
118.91, 1197.86, 87.95, 332.69, 166.82, 354.31, 1606.2, 291.69,
1249.39, 242.86, 1224.76, 124.8, 1411.4, 931.46, 1235.16,
281.03, 243.04, 122.92, 1477.23, 1265.99, 611.88, 842.57,
1560.03, 750.99, 441.94, 959.78, 958.17, 839.82, 1669.83,
574.74, 1224.5, 2036.75, 611.1, 1038.6, 1270.32, 1408.93,
819.38, 1488.12, 1609.87, 2077.33, 542.6, 1224.49, 897.21,
526.17, 1255.22, 1024.2, 1094.07, 883.58, 1474.83, 254.22,
685.91, 773.99, 369.43, 1067.1, 836.8, 161.94, 195.51, 71.42,
263.71, 67.52, 199.61, 1022.58, 633.86, 383.58, 1067.64,
489.93, 537.01, 685.4, 397.12, 656.74, 81.97, 661.04, 622.34,
588.71, 840.62, 486.15, 293.62, 1457.94, 365.49, 1087.82,
914.33, 1186.08, 621.2, 1609.02, 857.75, 821.89, 704.72,
422.94, 1526.63, 1017.96, 1205.47, 776.56, 1489.03, 2100.99,
842.79, 1763.54, 1767.1, 1970.65, 126.37, 1428.01, 2166.15,
1766.8, 1556.1, 854.55, 807.59, 455.12, 542.3, 146.07, 355.4
), AL = c(322.35, 400.01, 341.71, 247.13, 386.03, 303.59,
329.11, 291.79, 90.97, 242.22, 176.94, 25.2, 379.27, 300.27,
333.21, 66.67, 149.87, 288.18, 244.17, 110.47, 260.24, 137.08,
264.59, 138.14, 156.09, 164.43, 174.16, 180.24, 187.5, 218.4,
232.26, 236.66, 237.46, 276.76, 320.59, 280.23, 332.81, 260.59,
186.73, 21.85, 23.49, 239.13, 287.75, 329.91, 354.66, 331.84,
228.98, 189.62, 440.56, 254.17, 249.26, 288.15, 352.01, 288.97,
311.58, 149.65, 212.76, 361.95, 241.45, 33.54, 285.17, 328.53,
107.53, 366.27, 193.56, 399.93, 190.4, 259.81, 278.75, 30.48,
198.08, 144.58, 293.21, 18.2, 30.42, 101.3, 143.22, 150.39,
157.97, 162.33, 181.17, 189.07, 192.5, 195.37, 213.56, 252.36,
267, 287.81, 292.86, 331.3, 440.66, 256.56, 388.17, 220.55,
29.78, 204.53, 129.32, 146.66, 146.66, 352.75, 302.62, 363.56,
227.02, 166.22, 17.02, 342.32, 183.59, 302.71, 136.63, 291.63,
269.14, 288.31, 313.12, 37.56, 226.72, 321.45, 254.18, 22.25,
222.54, 65.71, 268.67, 266.68, 298.46, 346.94, 327.49, 197.9,
319.85, 115.98, 239.77, 146.98, 284.57, 244.23, 51.73, 345.15,
117.72, 262.48, 78.33, 322.76, 84.59, 230.36, 209.93, 193.75,
124.16, 220.12, 180.64, 185.51, 109.32, 118.5, 303.1, 305.81,
197.83, 284.21, 410.44, 294.64, 100.37, 259.55, 209.26, 312.33,
237.9, 301.94, 390.15, 222.38, 325.28, 192.68, 220.95, 269.43,
246.62, 231.59, 48.82, 422.12, 218.05, 420.4, 349.66, 399.67,
220.65, 286.88, 372.73, 232.54, 229.69, 323.48, 351.3, 311.23,
319.31, 97.29, 320.8, 77.96, 82.86, 286.81, 226.59, 387.55,
184.77, 279.99, 271.32, 248.51, 318.56, 296.44, 310.79, 152.49,
234.8, 172.95, 150.25, 186.86, 169.2, 265.44, 243.24, 264.69,
315.81, 205.8, 341.41, 327.86, 188.68, 258.05, 261.76, 353.18,
237.38, 220.84, 368.21, 276.15, 162.94, 146.64, 203.16, 14.34,
194.34, 254.6, 346.72, 157.3, 213.33, 283.81, 149.22, 201.29,
199.84, 238.64, 154.42, 164.19, 253.93, 318.49, 56.08, 391.3,
104.72, 146.42, 159.4, 162.62, 195.92, 196.38, 204.33, 206.7,
153.99, 219.81, 240.57, 222.94, 188.22, 275.02, 287.19, 298.18,
340.14, 197.7, 61.37, 319.62, 337.69, 299.58, 285.59, 321.92,
242.48, 347.76, 101.07, 148.03, 68.47, 84.84, 64.34, 77.29,
133.45, 271.7, 102.33, 129.41, 17.53, 183.84, 103.85, 250.44,
252.26, 187.07, 78.69, 102.9, 354.53, 97.1, 149.93, 188.25,
189.46, 59.45, 239.57, 43.97, 110.9, 83.41, 118.1, 321.24,
97.23, 249.88, 60.71, 306.19, 41.6, 352.85, 186.29, 308.79,
93.68, 81.01, 61.46, 295.45, 253.2, 122.38, 280.86, 312.01,
375.5, 147.31, 239.95, 191.63, 209.96, 333.97, 114.95, 244.9,
407.35, 203.7, 173.1, 254.06, 234.82, 204.85, 297.62, 321.97,
415.47, 135.65, 244.9, 224.3, 175.39, 251.04, 204.84, 273.52,
176.72, 294.97, 127.11, 171.48, 154.8, 123.14, 213.42, 167.36,
53.98, 48.88, 35.71, 131.85, 33.76, 49.9, 340.86, 211.29,
191.79, 177.94, 163.31, 268.5, 137.08, 132.37, 218.91, 27.32,
132.21, 155.59, 98.12, 140.1, 97.23, 48.94, 291.59, 121.83,
217.56, 182.87, 197.68, 124.24, 321.8, 171.55, 164.38, 176.18,
140.98, 254.44, 339.32, 241.09, 129.43, 297.81, 420.2, 280.93,
352.71, 353.42, 394.13, 25.27, 285.6, 361.03, 353.36, 311.22,
170.91, 161.52, 113.78, 135.58, 73.03, 177.7), RC = c(5L,
5L, 5L, 6L, 5L, 5L, 5L, 3L, 4L, 5L, 4L, 5L, 5L, 4L, 5L, 6L,
6L, 5L, 5L, 4L, 5L, 3L, 4L, 5L, 3L, 3L, 4L, 4L, 5L, 4L, 5L,
5L, 5L, 5L, 4L, 5L, 5L, 5L, 5L, 4L, 4L, 5L, 5L, 4L, 4L, 4L,
5L, 5L, 3L, 3L, 4L, 5L, 4L, 3L, 4L, 4L, 5L, 3L, 5L, 4L, 4L,
3L, 3L, 4L, 5L, 4L, 5L, 5L, 5L, 3L, 5L, 4L, 4L, 3L, 3L, 3L,
4L, 3L, 5L, 3L, 4L, 5L, 4L, 4L, 4L, 3L, 3L, 4L, 3L, 3L, 3L,
4L, 5L, 5L, 4L, 5L, 3L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 2L, 4L,
5L, 3L, 5L, 4L, 3L, 4L, 5L, 4L, 3L, 6L, 4L, 3L, 5L, 3L, 4L,
4L, 5L, 5L, 5L, 5L, 5L, 5L, 3L, 4L, 4L, 5L, 3L, 5L, 5L, 5L,
4L, 5L, 4L, 5L, 5L, 3L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
4L, 2L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 4L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 2L, 5L, 3L, 4L, 4L, 5L, 5L, 4L, 5L, 5L, 5L, 5L,
5L, 5L, 4L, 3L, 5L, 4L, 5L, 5L, 3L, 4L, 3L, 5L, 5L, 4L, 4L,
5L, 5L, 3L, 5L, 5L, 5L, 4L, 5L, 5L, 5L, 4L, 5L, 4L, 4L, 4L,
4L, 3L, 3L, 4L, 5L, 4L, 5L, 3L, 4L, 4L, 3L, 5L, 5L, 4L, 3L,
6L, 5L, 5L, 3L, 3L, 5L, 5L, 4L, 5L, 5L, 4L, 4L, 3L, 5L, 5L,
4L, 5L, 5L, 5L, 5L, 4L, 4L, 5L, 4L, 4L, 4L, 5L, 5L, 5L, 5L,
5L, 5L, 6L, 6L, 6L, 6L, 6L, 5L, 6L, 3L, 3L, 2L, 4L, 3L, 3L,
3L, 3L, 5L, 2L, 2L, 3L, 3L, 4L, 5L, 2L, 3L, 2L, 4L, 3L, 2L,
5L, 2L, 5L, 2L, 3L, 2L, 3L, 5L, 3L, 5L, 4L, 4L, 3L, 4L, 5L,
4L, 3L, 3L, 2L, 5L, 5L, 5L, 3L, 5L, 2L, 3L, 4L, 5L, 4L, 5L,
5L, 5L, 5L, 3L, 6L, 5L, 6L, 4L, 5L, 5L, 5L, 4L, 5L, 4L, 3L,
5L, 5L, 4L, 5L, 5L, 2L, 4L, 5L, 3L, 5L, 5L, 3L, 4L, 2L, 2L,
2L, 4L, 3L, 3L, 2L, 6L, 3L, 2L, 5L, 3L, 3L, 3L, 5L, 4L, 6L,
6L, 5L, 6L, 5L, 3L, 5L, 5L, 6L, 5L, 5L, 5L, 5L, 4L, 3L, 6L,
3L, 5L, 6L, 5L, 5L, 3L, 5L, 5L, 5L, 5L, 5L, 6L, 5L, 5L, 5L,
5L, 4L, 4L, 2L, 2L), CH = c(99796.6, 150717.35, 169751.56,
138012.75, 145077.46, 112201.58, 114565.78, 29620.4, 8114.84,
104093.06, 41066.73, 382.14, 149702.87, 92373.87, 158251.21,
6220.25, 34758.22, 112415.55, 82849.16, 9090.06, 51765.37,
16842.27, 88999.49, 44639.16, 17088.07, 16880.06, 36641.48,
33244.5, 60371.65, 43912.9, 77793.71, 86013.44, 81057.21,
116609.76, 111212.8, 83104.24, 136636.59, 112152.81, 43416.08,
283.33, 374.67, 90389.3, 114615.27, 127323.54, 122751.22,
105850.82, 91786.61, 23112.34, 133294.75, 27773.3, 49075.11,
93961.22, 144848.22, 77854.05, 65839.32, 24644.95, 61791.45,
74955.5, 92759.51, 964.97, 87895.4, 21552.75, 7974, 123189.55,
56441.2, 145209.81, 47723.32, 79965.64, 102406.65, 337.25,
66525.5, 9440, 79655.87, 176.68, 730.37, 5127.66, 20335.05,
16666.69, 38090.42, 20058.33, 11775.04, 50170.86, 36106.37,
61313.49, 43396.46, 47042.07, 49551.7, 91789.19, 48686.24,
64761.22, 156197.85, 55463.72, 153143.15, 64908.28, 506.14,
56835.13, 6120.06, 21167.83, 21211.43, 87971.16, 90657.94,
171831.58, 65430.27, 17854.84, 143.88, 91421.95, 34874.29,
38881.59, 3485.86, 99421.46, 36734.34, 92497.02, 104054.94,
940.84, 30819.4, 140446.17, 73149.38, 269.12, 68028.56, 2113.16,
74108.99, 61726.85, 103843.73, 115498.2, 152778.67, 40062.47,
137124.42, 13089.39, 35384.17, 13814.31, 101758.52, 72365.21,
1278.51, 133907.82, 21664.34, 89772.79, 5596.74, 127352.18,
8147.31, 58849.79, 39310.16, 16462, 16314.24, 67631.15, 46364.97,
64883.46, 9567.38, 10933.67, 107106.85, 85896.08, 36002.96,
99832.8, 96843.38, 168697.71, 11437, 89556.61, 64397.67,
175431.79, 99090.85, 137239, 177246.87, 16387.22, 129327.61,
49607.1, 84182.02, 103011.14, 76487.65, 68888.93, 2282.16,
40631.51, 84576.92, 136079.95, 102144.36, 170229.88, 80668.54,
122418.68, 36610.94, 54793.71, 71040.25, 119430.26, 124054.15,
158980.28, 115531.49, 7677, 52408.88, 5199.15, 1576.3, 117319.45,
65816.75, 107784.21, 21943.18, 44438.61, 79339.9, 94229.06,
78243.95, 87762.86, 102039.27, 27904.08, 33803.89, 30992.8,
22984.68, 52859.31, 32240, 96533.18, 110382.23, 90531.02,
156301.06, 74191.42, 101508.11, 126192.09, 25026.39, 52022.31,
54502.27, 54906.39, 46723.31, 64956.56, 164183.81, 106144.3,
15816.24, 25480.55, 40012.96, 187.89, 28777.54, 60948.7,
111351.64, 18846.81, 44388.99, 98196.75, 13827.13, 23302.71,
23032.36, 78314.21, 43668.82, 21560.18, 81402.92, 110253.4,
2468, 161127.06, 6728.38, 24954.59, 29634.28, 19529.65, 62234.38,
77694.07, 39340.43, 67121.62, 17881.17, 53538.79, 92126.96,
27319.28, 37817.88, 83791.37, 123852.55, 119991.03, 155539.82,
59573.35, 2017.04, 65310.24, 67034.04, 85421.53, 45188.09,
142873.37, 42077.58, 118492.3, 8899.7, 12988.53, 2414.63,
748.24, 1635.91, 1649.83, 12088.91, 21986.38, 5871.28, 17082.53,
89.46, 5935.65, 4201.11, 48657.16, 60375.11, 19427.75, 3066.9,
3634.67, 56680.85, 8585.62, 10017.71, 8010.08, 38352.11,
861.56, 63114, 778.52, 6436.22, 1594.19, 11462.7, 147823.51,
3663.95, 68565.01, 3541.49, 111886, 1550, 102544.23, 46836.23,
57453.23, 7184.43, 3564.13, 827.86, 81637.61, 63919.09, 29682.26,
69984.84, 139094.03, 66276.96, 10650.41, 36945, 35774.31,
44166.05, 73627.28, 6224.87, 41446.36, 91344.8, 30789.52,
45791.66, 66309.25, 21550.8, 37335.77, 76399.5, 59260.5,
139885.86, 12678.87, 32494.66, 43462.29, 28585.93, 58488.41,
38932.21, 72211.27, 37080.1, 120925.26, 8037.65, 39036.09,
12348, 11398.33, 76742.36, 45091.44, 2286.63, 1037.5, 377.59,
5550.86, 568, 2742.84, 40443.88, 31255.25, 15853.41, 12635.68,
24472.5, 31640.11, 25472.72, 8286.29, 44970.06, 514.17, 29406,
18771.87, 11593.36, 38816.45, 3866.89, 1358.91, 67884.5,
15016.07, 39352.47, 40707.85, 67124.98, 16286.1, 118673.4,
43579.93, 31756.41, 32294.47, 11045, 56989.65, 27077.35,
63791.55, 7803.23, 83200.54, 121846.69, 50495.22, 131891.93,
129093.86, 159164.54, 753.21, 99728.86, 175305.54, 151381.78,
114235.61, 8781.88, 31090, 11269.42, 11908.07, 554.04, 4928.65
), MW = c(427L, 456L, 331L, 308L, 479L, 411L, 330L, 158L,
60L, 360L, 352L, 17L, 432L, 488L, 550L, 76L, 179L, 541L,
443L, 66L, 219L, 109L, 318L, 191L, 220L, 111L, 258L, 173L,
355L, 250L, 318L, 424L, 350L, 420L, 422L, 421L, 573L, 521L,
199L, 16L, 23L, 399L, 347L, 521L, 549L, 336L, 231L, 104L,
491L, 131L, 161L, 357L, 479L, 261L, 305L, 152L, 308L, 520L,
437L, 26L, 450L, 99L, 64L, 556L, 176L, 526L, 311L, 379L,
382L, 14L, 354L, 70L, 442L, 13L, 32L, 57L, 193L, 117L, 308L,
157L, 60L, 222L, 195L, 328L, 237L, 282L, 241L, 217L, 325L,
265L, 506L, 260L, 475L, 382L, 22L, 222L, 45L, 239L, 239L,
252L, 395L, 518L, 319L, 105L, 15L, 396L, 158L, 128L, 20L,
293L, 125L, 365L, 259L, 14L, 112L, 515L, 274L, 17L, 332L,
27L, 139L, 297L, 474L, 298L, 567L, 202L, 468L, 87L, 275L,
132L, 441L, 333L, 23L, 452L, 221L, 431L, 63L, 434L, 80L,
324L, 145L, 189L, 80L, 438L, 234L, 351L, 59L, 83L, 474L,
263L, 224L, 510L, 479L, 555L, 74L, 327L, 350L, 563L, 519L,
507L, 534L, 83L, 546L, 289L, 301L, 506L, 375L, 388L, 36L,
155L, 418L, 540L, 353L, 522L, 368L, 523L, 96L, 255L, 277L,
357L, 350L, 487L, 347L, 86L, 269L, 41L, 24L, 311L, 398L,
422L, 154L, 221L, 278L, 365L, 304L, 257L, 324L, 195L, 290L,
191L, 176L, 313L, 260L, 471L, 486L, 415L, 579L, 439L, 361L,
433L, 184L, 285L, 273L, 228L, 288L, 386L, 536L, 500L, 53L,
122L, 259L, 10L, 125L, 246L, 419L, 188L, 217L, 457L, 76L,
257L, 257L, 327L, 155L, 120L, 339L, 480L, 34L, 552L, 74L,
124L, 269L, 216L, 301L, 374L, 131L, 243L, 169L, 240L, 390L,
137L, 229L, 421L, 334L, 482L, 496L, 236L, 24L, 225L, 211L,
406L, 194L, 504L, 243L, 541L, 88L, 156L, 61L, 8L, 25L, 23L,
149L, 62L, 56L, 103L, 10L, 48L, 35L, 290L, 283L, 164L, 92L,
16L, 306L, 118L, 84L, 70L, 214L, 24L, 356L, 28L, 46L, 8L,
150L, 516L, 38L, 405L, 80L, 339L, 50L, 338L, 258L, 326L,
124L, 44L, 12L, 212L, 323L, 239L, 447L, 529L, 425L, 84L,
228L, 240L, 304L, 332L, 64L, 241L, 316L, 226L, 163L, 256L,
87L, 153L, 409L, 315L, 534L, 168L, 205L, 294L, 190L, 345L,
244L, 342L, 156L, 491L, 175L, 230L, 100L, 79L, 385L, 351L,
57L, 23L, 14L, 38L, 40L, 67L, 180L, 290L, 140L, 42L, 267L,
267L, 171L, 66L, 348L, 40L, 303L, 166L, 46L, 292L, 45L, 19L,
358L, 162L, 358L, 311L, 408L, 114L, 439L, 191L, 192L, 181L,
168L, 348L, 119L, 284L, 51L, 325L, 340L, 238L, 455L, 478L,
557L, 25L, 411L, 608L, 458L, 465L, 43L, 293L, 128L, 71L,
15L, 33L), MD = c(594L, 607L, 703L, 603L, 565L, 512L, 627L,
501L, 382L, 686L, 389L, 126L, 523L, 461L, 575L, 184L, 299L,
417L, 337L, 265L, 389L, 246L, 575L, 354L, 284L, 282L, 305L,
468L, 330L, 377L, 476L, 589L, 497L, 529L, 520L, 470L, 546L,
601L, 607L, 129L, 111L, 426L, 620L, 510L, 470L, 491L, 527L,
333L, 541L, 359L, 485L, 435L, 561L, 538L, 341L, 362L, 437L,
521L, 614L, 121L, 433L, 478L, 256L, 459L, 450L, 497L, 290L,
395L, 495L, 58L, 376L, 240L, 367L, 100L, 120L, 308L, 301L,
280L, 235L, 264L, 463L, 540L, 369L, 352L, 340L, 343L, 424L,
557L, 307L, 471L, 568L, 493L, 725L, 498L, 113L, 441L, 252L,
251L, 252L, 615L, 388L, 614L, 387L, 317L, 65L, 529L, 555L,
702L, 305L, 634L, 567L, 525L, 641L, 135L, 495L, 497L, 480L,
51L, 415L, 178L, 602L, 365L, 500L, 685L, 663L, 562L, 587L,
357L, 301L, 250L, 450L, 415L, 137L, 408L, 204L, 368L, 164L,
502L, 200L, 288L, 314L, 212L, 482L, 385L, 512L, 528L, 342L,
335L, 435L, 556L, 351L, 402L, 377L, 605L, 231L, 495L, 381L,
672L, 575L, 669L, 694L, 378L, 485L, 325L, 508L, 439L, 393L,
370L, 173L, 480L, 428L, 522L, 690L, 734L, 583L, 465L, 653L,
424L, 369L, 576L, 598L, 610L, 576L, 169L, 401L, 232L, 152L,
710L, 383L, 501L, 233L, 380L, 416L, 645L, 621L, 561L, 561L,
320L, 256L, 376L, 257L, 364L, 259L, 381L, 529L, 497L, 728L,
517L, 630L, 562L, 316L, 403L, 415L, 496L, 299L, 343L, 591L,
394L, 373L, 331L, 302L, 176L, 583L, 416L, 534L, 255L, 403L,
462L, 366L, 209L, 210L, 363L, 394L, 266L, 473L, 448L, 183L,
590L, 207L, 449L, 207L, 200L, 441L, 419L, 440L, 514L, 252L,
577L, 452L, 333L, 309L, 488L, 540L, 452L, 665L, 479L, 278L,
616L, 618L, 348L, 433L, 509L, 340L, 478L, 215L, 271L, 319L,
196L, 164L, 251L, 303L, 585L, 229L, 294L, 118L, 248L, 192L,
293L, 486L, 413L, 283L, 334L, 400L, 145L, 171L, 243L, 360L,
99L, 469L, 196L, 365L, 194L, 198L, 455L, 235L, 380L, 120L,
504L, 110L, 475L, 248L, 361L, 145L, 150L, 145L, 581L, 540L,
301L, 361L, 518L, 398L, 254L, 326L, 330L, 286L, 610L, 237L,
418L, 617L, 274L, 375L, 337L, 378L, 366L, 447L, 545L, 507L,
212L, 346L, 363L, 280L, 367L, 266L, 323L, 393L, 460L, 246L,
338L, 311L, 227L, 325L, 262L, 93L, 104L, 98L, 185L, 64L,
118L, 503L, 359L, 427L, 398L, 251L, 342L, 275L, 235L, 276L,
53L, 342L, 314L, 500L, 474L, 214L, 200L, 360L, 216L, 272L,
297L, 323L, 277L, 375L, 339L, 290L, 316L, 260L, 458L, 580L,
541L, 285L, 481L, 642L, 417L, 567L, 521L, 535L, 93L, 449L,
515L, 501L, 443L, 350L, 244L, 357L, 330L, 113L, 196L), `W/D` = c(0.72,
0.75, 0.47, 0.51, 0.85, 0.8, 0.53, 0.32, 0.16, 0.52, 0.9,
0.13, 0.83, 1.06, 0.96, 0.41, 0.6, 1.3, 1.31, 0.25, 0.56,
0.44, 0.55, 0.54, 0.77, 0.39, 0.85, 0.37, 1.08, 0.66, 0.67,
0.72, 0.7, 0.79, 0.81, 0.9, 1.05, 0.87, 0.33, 0.12, 0.21,
0.94, 0.56, 1.02, 1.17, 0.68, 0.44, 0.31, 0.91, 0.36, 0.33,
0.82, 0.85, 0.49, 0.89, 0.42, 0.7, 1, 0.71, 0.21, 1.04, 0.21,
0.25, 1.21, 0.39, 1.06, 1.07, 0.96, 0.77, 0.24, 0.94, 0.29,
1.2, 0.13, 0.27, 0.19, 0.64, 0.42, 1.31, 0.59, 0.13, 0.41,
0.53, 0.93, 0.7, 0.82, 0.57, 0.39, 1.06, 0.56, 0.89, 0.53,
0.66, 0.77, 0.19, 0.5, 0.18, 0.95, 0.95, 0.41, 1.02, 0.84,
0.82, 0.33, 0.23, 0.75, 0.28, 0.18, 0.07, 0.46, 0.22, 0.7,
0.4, 0.1, 0.23, 1.04, 0.57, 0.33, 0.8, 0.15, 0.23, 0.81,
0.95, 0.44, 0.86, 0.36, 0.8, 0.24, 0.91, 0.53, 0.98, 0.8,
0.17, 1.11, 1.08, 1.17, 0.38, 0.86, 0.4, 1.12, 0.46, 0.89,
0.17, 1.14, 0.46, 0.66, 0.17, 0.25, 1.09, 0.47, 0.64, 1.27,
1.27, 0.92, 0.32, 0.66, 0.92, 0.84, 0.9, 0.76, 0.77, 0.22,
1.13, 0.89, 0.59, 1.15, 0.95, 1.05, 0.21, 0.32, 0.98, 1.03,
0.51, 0.71, 0.63, 1.12, 0.15, 0.6, 0.75, 0.62, 0.59, 0.8,
0.6, 0.51, 0.67, 0.18, 0.16, 0.44, 1.04, 0.84, 0.66, 0.58,
0.67, 0.57, 0.49, 0.46, 0.58, 0.61, 1.13, 0.51, 0.68, 0.86,
1, 1.24, 0.92, 0.84, 0.8, 0.85, 0.57, 0.77, 0.58, 0.71, 0.66,
0.46, 0.96, 1.13, 0.91, 1.27, 0.14, 0.37, 0.86, 0.06, 0.21,
0.59, 0.78, 0.74, 0.54, 0.99, 0.21, 1.23, 1.22, 0.9, 0.39,
0.45, 0.72, 1.07, 0.19, 0.94, 0.36, 0.28, 1.3, 1.08, 0.68,
0.89, 0.3, 0.47, 0.67, 0.42, 0.86, 0.41, 0.74, 0.86, 0.62,
1.07, 0.75, 0.49, 0.09, 0.37, 0.34, 1.17, 0.45, 0.99, 0.71,
1.13, 0.41, 0.58, 0.19, 0.04, 0.15, 0.09, 0.49, 0.11, 0.24,
0.35, 0.08, 0.19, 0.18, 0.99, 0.58, 0.4, 0.33, 0.05, 0.76,
0.81, 0.49, 0.29, 0.59, 0.24, 0.76, 0.14, 0.13, 0.04, 0.76,
1.13, 0.16, 1.07, 0.67, 0.67, 0.45, 0.71, 1.04, 0.9, 0.86,
0.29, 0.08, 0.36, 0.6, 0.79, 1.24, 1.02, 1.07, 0.33, 0.7,
0.73, 1.06, 0.54, 0.27, 0.58, 0.51, 0.82, 0.43, 0.76, 0.23,
0.42, 0.91, 0.58, 1.05, 0.79, 0.59, 0.81, 0.68, 0.94, 0.92,
1.06, 0.4, 1.07, 0.71, 0.68, 0.32, 0.35, 1.18, 1.34, 0.61,
0.22, 0.14, 0.21, 0.62, 0.57, 0.36, 0.81, 0.33, 0.11, 1.06,
0.78, 0.62, 0.28, 1.26, 0.75, 0.89, 0.53, 0.09, 0.62, 0.21,
0.1, 0.99, 0.75, 1.32, 1.05, 1.26, 0.41, 1.17, 0.56, 0.66,
0.57, 0.65, 0.76, 0.21, 0.52, 0.18, 0.68, 0.53, 0.57, 0.8,
0.92, 1.04, 0.27, 0.92, 1.18, 0.91, 1.05, 0.12, 1.2, 0.36,
0.22, 0.13, 0.17)), .Names = c("ATA", "AEA", "TL", "AL",
"RC", "CH", "MW", "MD", "W/D"), row.names = c(NA, -396L), class =
c("tbl_df",
"tbl", "data.frame"))
I tried to do this with ggcorr function and I ended up with a graph, which I am very happy of. But I don't understand why it look to have "avoided" to do the correlation between W/D and other variables.
This is the function that I run:
ggcorr(df,label = TRUE,name = "Spearman correlation coeff. (ρ)",
label_size = 3, hjust = 0.75, size = 5, color = "grey40", low = "#3399FF",
mid = "#FFFF66", high = "#CC0033", method = c("pairwise", "spearman"))+
theme(legend.title = element_text(size = 11))
And I got this warning message:
Warning messages:
1: Removed 8 rows containing missing values (geom_tile).
2: Removed 8 rows containing missing values (geom_text).
It seems to remove the correlations between W/D and all the other varaiables.I think that the problem is in the last column W/D.
graph
Thanks for updating. Next time, I recommend you also include the libraries you loaded. Anyways, here is the full reproducible solution which I ran successfully on my machine with no errors. Have a look at the package versions I have installed which is from sessionInfo(). Perhaps try doing install.packages() for both the packages loaded and see if you still get the same error after updating to the latest versions. My first guess was that you were missing values, but as you can see colSums(is.na(df)) I checked to see if there were any missing values in any of the columns, but there were none.
This is how I got this fully reproducible example below (I just deleted the df part because it was too long and you already have it in the question):
library(reprex); reprex(venue='so', si=TRUE)
library(ggplot2)
library(GGally)
#> Warning: package 'GGally' was built under R version 3.4.1
ggcorr(df,label = TRUE,name = "Spearman correlation coeff. (ρ)",
label_size = 3, hjust = 0.75, size = 5, color = "grey40", low = "#3399FF",
mid = "#FFFF66", high = "#CC0033", method = c("pairwise", "spearman"))+
theme(legend.title = element_text(size = 11))
colSums(is.na(df))
#> ATA AEA TL AL RC CH MW MD W/D
#> 0 0 0 0 0 0 0 0 0
devtools::session_info()
#> Warning in as.POSIXlt.POSIXct(Sys.time()): unknown timezone 'default/
#> America/Vancouver'
#> Session info -------------------------------------------------------------
#> setting value
#> version R version 3.4.0 (2017-04-21)
#> system x86_64, darwin15.6.0
#> ui X11
#> language (EN)
#> collate en_US.UTF-8
#> tz <NA>
#> date 2017-09-26
#> Packages -----------------------------------------------------------------
#> package * version date source
#> backports 1.1.0 2017-05-22 CRAN (R 3.4.0)
#> base * 3.4.0 2017-04-21 local
#> colorspace 1.3-2 2016-12-14 CRAN (R 3.4.0)
#> compiler 3.4.0 2017-04-21 local
#> datasets * 3.4.0 2017-04-21 local
#> devtools 1.13.3 2017-08-02 CRAN (R 3.4.1)
#> digest 0.6.12 2017-01-27 CRAN (R 3.4.0)
#> evaluate 0.10.1 2017-06-24 CRAN (R 3.4.1)
#> GGally * 1.3.2 2017-08-02 CRAN (R 3.4.1)
#> ggplot2 * 2.2.1 2016-12-30 CRAN (R 3.4.0)
#> graphics * 3.4.0 2017-04-21 local
#> grDevices * 3.4.0 2017-04-21 local
#> grid 3.4.0 2017-04-21 local
#> gtable 0.2.0 2016-02-26 CRAN (R 3.4.0)
#> htmltools 0.3.6 2017-04-28 CRAN (R 3.4.0)
#> knitr 1.17 2017-08-10 CRAN (R 3.4.1)
#> labeling 0.3 2014-08-23 CRAN (R 3.4.0)
#> lazyeval 0.2.0 2016-06-12 CRAN (R 3.4.0)
#> magrittr 1.5 2014-11-22 CRAN (R 3.4.0)
#> memoise 1.1.0 2017-04-21 CRAN (R 3.4.0)
#> methods * 3.4.0 2017-04-21 local
#> munsell 0.4.3 2016-02-13 CRAN (R 3.4.0)
#> plyr 1.8.4 2016-06-08 CRAN (R 3.4.0)
#> RColorBrewer 1.1-2 2014-12-07 CRAN (R 3.4.0)
#> Rcpp 0.12.12 2017-07-15 cran (#0.12.12)
#> reshape 0.8.7 2017-08-06 CRAN (R 3.4.1)
#> rlang 0.1.2 2017-08-09 CRAN (R 3.4.1)
#> rmarkdown 1.6 2017-06-15 CRAN (R 3.4.0)
#> rprojroot 1.2 2017-01-16 CRAN (R 3.4.0)
#> scales 0.5.0 2017-08-24 CRAN (R 3.4.1)
#> stats * 3.4.0 2017-04-21 local
#> stringi 1.1.5 2017-04-07 CRAN (R 3.4.0)
#> stringr 1.2.0 2017-02-18 CRAN (R 3.4.0)
#> tibble 1.3.4 2017-08-22 CRAN (R 3.4.1)
#> tools 3.4.0 2017-04-21 local
#> utils * 3.4.0 2017-04-21 local
#> withr 2.0.0 2017-07-28 CRAN (R 3.4.1)
#> yaml 2.1.14 2016-11-12 CRAN (R 3.4.0)
How do you calculate the cut-off of a rank-size distribution, i.e. the x which splits the distribution so that the top x% categories contain 1-x% of observations? For example, if the cut-off is 20%, the top 20% categories contain 80% of the observations.
In the sample below, the categories are cbsa_code, frequency is Freq, and category rank by frequency is rank (some ranks can be equal and decimal because they were calculated with ties.method = "average"):
structure(list(cbsa_code = c("35620", "41860", "31080", "41940",
"14460", "47900", "16980", "42660", "33100", "19100", "37980",
"12420", "12060", "41740", "26420", "38900", "38060", "19740",
"33460", "29820", "19820", "36740", "45300", "14500", "14860",
"12580", "17140", "40900", "38300", "41620", "28140", "34980",
"41180", "20500", "39580", "16740", "17460", "40140", "18140",
"39340", "41700", "27260", "33340", "26900", "31540", "10580",
"11460", "32820", "35380", "39300", "35300", "42100", "12540",
"36420", "40060", "45940", "46140", "25540", "31140", "40380",
"42200", "46520", "15380", "24340", "35840", "47260", "46060",
"17820", "49340", "31700", "36540", "37100", "10420", "15980",
"16700", "19780", "30780", "42220", "10740", "22660", "23540",
"28940", "39900", "13820", "16580", "16860", "14260", "16940",
"24860", "29620", "34940", "45780", "16820", "43620", "11700",
"23420", "25420", "34820", "41500", "12940", "22220", "26620",
"33860", "41540", "44060", "48900", "11260", "14740", "20100",
"21660", "27060", "10900", "14580", "15540", "17900", "21340",
"24660", "29540", "37340", "38860", "44140", "45220", "19380",
"19660", "26980", "29940", "30460", "36260", "42020", "42340",
"46340", "11540", "12020", "13380", "17020", "17200", "18700",
"24580", "24780", "25500", "25900", "26820", "27540", "27940",
"32780", "34900", "35980", "37860", "42540", "43900", "44300",
"45060", "46700", "48620", "11100", "12220", "12300", "13460",
"18180", "19340", "20780", "22140", "27140", "27220", "28420",
"28700", "28740", "30700", "33260", "33780", "34580", "36860",
"39460", "41420", "44700", "47380", "48660", "49180", "12700",
"13100", "13780", "13980", "17660", "18580", "20020", "20260",
"21140", "21500", "23060", "23860", "24060", "25180", "25200",
"25860", "26380", "26500", "26740", "27980", "29340", "29460",
"31060", "36100", "36780", "37460", "38940", "40420", "42140",
"43780", "44180", "44500", "45860", "46660", "48700", "49620",
"10780", "11900", "12260", "13220", "13900", "14100", "14540",
"15940", "16180", "16300", "17340", "17780", "17860", "17980",
"18660", "20140", "20220", "20420", "20700", "21260", "22020",
"22500", "22520", "22900", "23180", "23580", "23820", "24300",
"24420", "24540", "24900", "24940", "25060", "25940", "28020",
"28060", "28580", "29300", "29660", "30020", "30140", "30420",
"30860", "30980", "31180", "31340", "31900", "32140", "32580",
"33140", "33220", "33540", "36140", "36500", "36700", "36980",
"37900", "38540", "39140", "39420", "39540", "39660", "39740",
"40660", "41140", "42700", "43060", "43100", "43380", "43580",
"44100", "44260", "44920", "45460", "45900", "46020", "46540",
"47460", "49300", "49420", "10100", "10140", "10460", "10620",
"10700", "11500", "11740", "11820", "12620", "12740", "12900",
"12980", "13140", "13180", "13740", "14010", "14140", "14380",
"14700", "15220", "15260", "15500", "15620", "15740", "16100",
"16220", "16540", "17220", "17300", "17580", "17740", "18020",
"18220", "18260", "19060", "19140", "19180", "19300", "19580",
"20380", "20660", "20740", "20820", "21220", "21540", "21580",
"21700", "21780", "21840", "21900", "22180", "22420", "23300",
"23460", "23660", "23900", "24020", "24220", "24260", "24620",
"24640", "25620", "26780", "26860", "27420", "27460", "27900",
"28100", "28380", "28660", "28780", "29060", "29100", "29200",
"29380", "29700", "29980", "30300", "30340", "31020", "31300",
"31380", "31940", "32220", "32260", "32380", "33700", "33740",
"34100", "34340", "34460", "34620", "34700", "34780", "34860",
"35460", "35740", "36460", "36940", "37120", "38240", "38380",
"38820", "39020", "39060", "39820", "39940", "39980", "40220",
"40260", "40340", "40860", "40980", "41060", "41820", "42820",
"42860", "42940", "43140", "43260", "43340", "43420", "43740",
"44220", "44420", "44460", "44660", "45180", "45340", "45380",
"45620", "45820", "46220", "46300", "46740", "46980", "47180",
"47220", "47240", "47300", "47620", "47700", "47940", "48020",
"48060", "48140", "48260", "48580", "48780", "49080", "49220",
"49660", "10180", "10220", "10300", "10500", "10540", "10660",
"10820", "10860", "10940", "10980", "11020", "11060", "11140",
"11180", "11220", "11380", "11420", "11580", "11620", "11660",
"11680", "11780", "11860", "11940", "11980", "12100", "12140",
"12180", "12380", "12460", "12660", "12680", "12780", "12820",
"12860", "13020", "13060", "13260", "13300", "13340", "13420",
"13500", "13540", "13620", "13660", "13700", "13720", "13940",
"14020", "14180", "14220", "14340", "14420", "14620", "14660",
"14720", "14780", "14820", "15020", "15060", "15100", "15180",
"15340", "15420", "15460", "15580", "15660", "15680", "15700",
"15780", "15820", "15860", "15900", "16020", "16060", "16260",
"16340", "16380", "16460", "16500", "16620", "16660", "17060",
"17260", "17380", "17420", "17500", "17540", "17700", "18060",
"18100", "18300", "18380", "18420", "18460", "18500", "18620",
"18740", "18780", "18820", "18860", "18880", "18900", "18980",
"19000", "19220", "19260", "19420", "19460", "19500", "19540",
"19620", "19700", "19760", "19860", "19940", "19980", "20060",
"20180", "20300", "20340", "20460", "20540", "20580", "20900",
"20940", "20980", "21020", "21060", "21120", "21180", "21300",
"21380", "21420", "21460", "21740", "21820", "21980", "22060",
"22100", "22260", "22280", "22300", "22340", "22380", "22540",
"22580", "22620", "22700", "22780", "22800", "22820", "22860",
"23140", "23240", "23340", "23380", "23500", "23620", "23700",
"23780", "23940", "23980", "24100", "24140", "24380", "24460",
"24500", "24700", "24740", "24820", "24980", "25100", "25220",
"25260", "25300", "25460", "25580", "25700", "25720", "25740",
"25760", "25780", "25820", "25840", "25880", "25980", "26020",
"26090", "26140", "26220", "26300", "26340", "26460", "26540",
"26580", "26660", "26700", "26940", "26960", "27020", "27100",
"27160", "27180", "27300", "27340", "27380", "27500", "27600",
"27620", "27700", "27740", "27780", "27860", "27920", "28180",
"28260", "28300", "28340", "28500", "28540", "28620", "28820",
"28860", "28900", "29020", "29180", "29260", "29420", "29500",
"29740", "29780", "29860", "29900", "30060", "30220", "30260",
"30280", "30380", "30580", "30620", "30660", "30820", "30880",
"30900", "30940", "31220", "31260", "31420", "31460", "31500",
"31580", "31620", "31660", "31680", "31740", "31820", "31860",
"31930", "31980", "32000", "32020", "32100", "32180", "32280",
"32300", "32340", "32460", "32500", "32540", "32620", "32660",
"32700", "32740", "32860", "32900", "32940", "32980", "33020",
"33060", "33180", "33300", "33420", "33500", "33580", "33620",
"33660", "33940", "33980", "34020", "34060", "34140", "34180",
"34220", "34260", "34300", "34380", "34420", "34500", "34540",
"34660", "34740", "35020", "35060", "35100", "35140", "35220",
"35260", "35420", "35440", "35500", "35580", "35660", "35700",
"35820", "35860", "35900", "35940", "36020", "36220", "36300",
"36340", "36380", "36580", "36620", "36660", "36820", "36830",
"36840", "36900", "37020", "37060", "37080", "37140", "37220",
"37260", "37300", "37420", "37500", "37540", "37580", "37620",
"37660", "37740", "37780", "37940", "38100", "38180", "38220",
"38260", "38340", "38420", "38460", "38500", "38580", "38620",
"38700", "38740", "38780", "38840", "38920", "39220", "39260",
"39380", "39500", "39700", "39780", "39860", "40080", "40100",
"40180", "40300", "40460", "40540", "40580", "40620", "40700",
"40740", "40780", "40820", "40940", "41100", "41220", "41400",
"41460", "41660", "41760", "41780", "42300", "42380", "42420",
"42460", "42620", "42680", "42740", "42780", "42900", "42980",
"43020", "43180", "43220", "43300", "43320", "43460", "43500",
"43660", "43700", "43760", "43940", "43980", "44020", "44340",
"44540", "44580", "44620", "44740", "44780", "44860", "44900",
"44940", "44980", "45000", "45020", "45140", "45500", "45520",
"45540", "45580", "45660", "45700", "45740", "45980", "46100",
"46180", "46380", "46460", "46500", "46620", "46780", "46820",
"46860", "46900", "47020", "47080", "47340", "47420", "47540",
"47580", "47660", "47780", "47820", "47920", "47980", "48100",
"48180", "48220", "48300", "48460", "48540", "48820", "48940",
"48980", "49020", "49100", "49260", "49380", "49460", "49700",
"49740", "49780", "49820"), Freq = c(1812L, 1558L, 1052L, 622L,
514L, 455L, 395L, 393L, 311L, 266L, 261L, 259L, 249L, 213L, 204L,
156L, 151L, 141L, 95L, 92L, 91L, 91L, 84L, 76L, 71L, 70L, 68L,
66L, 64L, 64L, 61L, 59L, 52L, 50L, 46L, 45L, 44L, 44L, 40L, 38L,
38L, 36L, 35L, 34L, 32L, 31L, 30L, 30L, 29L, 28L, 27L, 26L, 25L,
25L, 25L, 24L, 23L, 21L, 21L, 21L, 21L, 21L, 20L, 20L, 20L, 20L,
19L, 17L, 17L, 16L, 16L, 16L, 15L, 15L, 15L, 15L, 15L, 15L, 14L,
14L, 14L, 14L, 14L, 13L, 13L, 13L, 12L, 12L, 12L, 12L, 12L, 12L,
11L, 11L, 10L, 10L, 10L, 10L, 10L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
8L, 8L, 8L, 8L, 8L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), rank = c(1, 2, 3,
4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21.5, 21.5, 23, 24, 25, 26, 27, 28, 29.5, 29.5, 31, 32, 33, 34,
35, 36, 37.5, 37.5, 39, 40.5, 40.5, 42, 43, 44, 45, 46, 47.5,
47.5, 49, 50, 51, 52, 54, 54, 54, 56, 57, 60, 60, 60, 60, 60,
64.5, 64.5, 64.5, 64.5, 67, 68.5, 68.5, 71, 71, 71, 75.5, 75.5,
75.5, 75.5, 75.5, 75.5, 81, 81, 81, 81, 81, 85, 85, 85, 89.5,
89.5, 89.5, 89.5, 89.5, 89.5, 93.5, 93.5, 97, 97, 97, 97, 97,
103, 103, 103, 103, 103, 103, 103, 109, 109, 109, 109, 109, 117,
117, 117, 117, 117, 117, 117, 117, 117, 117, 117, 127, 127, 127,
127, 127, 127, 127, 127, 127, 143, 143, 143, 143, 143, 143, 143,
143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143,
143, 143, 143, 166.5, 166.5, 166.5, 166.5, 166.5, 166.5, 166.5,
166.5, 166.5, 166.5, 166.5, 166.5, 166.5, 166.5, 166.5, 166.5,
166.5, 166.5, 166.5, 166.5, 166.5, 166.5, 166.5, 166.5, 196.5,
196.5, 196.5, 196.5, 196.5, 196.5, 196.5, 196.5, 196.5, 196.5,
196.5, 196.5, 196.5, 196.5, 196.5, 196.5, 196.5, 196.5, 196.5,
196.5, 196.5, 196.5, 196.5, 196.5, 196.5, 196.5, 196.5, 196.5,
196.5, 196.5, 196.5, 196.5, 196.5, 196.5, 196.5, 196.5, 254.5,
254.5, 254.5, 254.5, 254.5, 254.5, 254.5, 254.5, 254.5, 254.5,
254.5, 254.5, 254.5, 254.5, 254.5, 254.5, 254.5, 254.5, 254.5,
254.5, 254.5, 254.5, 254.5, 254.5, 254.5, 254.5, 254.5, 254.5,
254.5, 254.5, 254.5, 254.5, 254.5, 254.5, 254.5, 254.5, 254.5,
254.5, 254.5, 254.5, 254.5, 254.5, 254.5, 254.5, 254.5, 254.5,
254.5, 254.5, 254.5, 254.5, 254.5, 254.5, 254.5, 254.5, 254.5,
254.5, 254.5, 254.5, 254.5, 254.5, 254.5, 254.5, 254.5, 254.5,
254.5, 254.5, 254.5, 254.5, 254.5, 254.5, 254.5, 254.5, 254.5,
254.5, 254.5, 254.5, 254.5, 254.5, 254.5, 254.5, 370.5, 370.5,
370.5, 370.5, 370.5, 370.5, 370.5, 370.5, 370.5, 370.5, 370.5,
370.5, 370.5, 370.5, 370.5, 370.5, 370.5, 370.5, 370.5, 370.5,
370.5, 370.5, 370.5, 370.5, 370.5, 370.5, 370.5, 370.5, 370.5,
370.5, 370.5, 370.5, 370.5, 370.5, 370.5, 370.5, 370.5, 370.5,
370.5, 370.5, 370.5, 370.5, 370.5, 370.5, 370.5, 370.5, 370.5,
370.5, 370.5, 370.5, 370.5, 370.5, 370.5, 370.5, 370.5, 370.5,
370.5, 370.5, 370.5, 370.5, 370.5, 370.5, 370.5, 370.5, 370.5,
370.5, 370.5, 370.5, 370.5, 370.5, 370.5, 370.5, 370.5, 370.5,
370.5, 370.5, 370.5, 370.5, 370.5, 370.5, 370.5, 370.5, 370.5,
370.5, 370.5, 370.5, 370.5, 370.5, 370.5, 370.5, 370.5, 370.5,
370.5, 370.5, 370.5, 370.5, 370.5, 370.5, 370.5, 370.5, 370.5,
370.5, 370.5, 370.5, 370.5, 370.5, 370.5, 370.5, 370.5, 370.5,
370.5, 370.5, 370.5, 370.5, 370.5, 370.5, 370.5, 370.5, 370.5,
370.5, 370.5, 370.5, 370.5, 370.5, 370.5, 370.5, 370.5, 370.5,
370.5, 370.5, 370.5, 370.5, 370.5, 370.5, 370.5, 370.5, 370.5,
370.5, 370.5, 370.5, 370.5, 370.5, 370.5, 370.5, 370.5, 370.5,
370.5, 370.5, 370.5, 370.5, 370.5, 370.5, 447, 448, 449, 450,
451, 452, 453, 454, 455, 456, 457, 458, 459, 460, 461, 462, 463,
464, 465, 466, 467, 468, 469, 470, 471, 472, 473, 474, 475, 476,
477, 478, 479, 480, 481, 482, 483, 484, 485, 486, 487, 488, 489,
490, 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, 501, 502,
503, 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, 515,
516, 517, 518, 519, 520, 521, 522, 523, 524, 525, 526, 527, 528,
529, 530, 531, 532, 533, 534, 535, 536, 537, 538, 539, 540, 541,
542, 543, 544, 545, 546, 547, 548, 549, 550, 551, 552, 553, 554,
555, 556, 557, 558, 559, 560, 561, 562, 563, 564, 565, 566, 567,
568, 569, 570, 571, 572, 573, 574, 575, 576, 577, 578, 579, 580,
581, 582, 583, 584, 585, 586, 587, 588, 589, 590, 591, 592, 593,
594, 595, 596, 597, 598, 599, 600, 601, 602, 603, 604, 605, 606,
607, 608, 609, 610, 611, 612, 613, 614, 615, 616, 617, 618, 619,
620, 621, 622, 623, 624, 625, 626, 627, 628, 629, 630, 631, 632,
633, 634, 635, 636, 637, 638, 639, 640, 641, 642, 643, 644, 645,
646, 647, 648, 649, 650, 651, 652, 653, 654, 655, 656, 657, 658,
659, 660, 661, 662, 663, 664, 665, 666, 667, 668, 669, 670, 671,
672, 673, 674, 675, 676, 677, 678, 679, 680, 681, 682, 683, 684,
685, 686, 687, 688, 689, 690, 691, 692, 693, 694, 695, 696, 697,
698, 699, 700, 701, 702, 703, 704, 705, 706, 707, 708, 709, 710,
711, 712, 713, 714, 715, 716, 717, 718, 719, 720, 721, 722, 723,
724, 725, 726, 727, 728, 729, 730, 731, 732, 733, 734, 735, 736,
737, 738, 739, 740, 741, 742, 743, 744, 745, 746, 747, 748, 749,
750, 751, 752, 753, 754, 755, 756, 757, 758, 759, 760, 761, 762,
763, 764, 765, 766, 767, 768, 769, 770, 771, 772, 773, 774, 775,
776, 777, 778, 779, 780, 781, 782, 783, 784, 785, 786, 787, 788,
789, 790, 791, 792, 793, 794, 795, 796, 797, 798, 799, 800, 801,
802, 803, 804, 805, 806, 807, 808, 809, 810, 811, 812, 813, 814,
815, 816, 817, 818, 819, 820, 821, 822, 823, 824, 825, 826, 827,
828, 829, 830, 831, 832, 833, 834, 835, 836, 837, 838, 839, 840,
841, 842, 843, 844, 845, 846, 847, 848, 849, 850, 851, 852, 853,
854, 855, 856, 857, 858, 859, 860, 861, 862, 863, 864, 865, 866,
867, 868, 869, 870, 871, 872, 873, 874, 875, 876, 877, 878, 879,
880, 881, 882, 883, 884, 885, 886, 887, 888, 889, 890, 891, 892,
893, 894, 895, 896, 897, 898, 899, 900, 901, 902, 903, 904, 905,
906, 907, 908, 909, 910, 911, 912, 913, 914, 915, 916, 917)), .Names = c("cbsa_code",
"Freq", "rank"), row.names = c(597L, 742L, 488L, 743L, 103L,
878L, 159L, 756L, 539L, 207L, 654L, 54L, 46L, 738L, 378L, 676L,
655L, 223L, 547L, 459L, 226L, 623L, 820L, 104L, 114L, 57L, 162L,
722L, 661L, 735L, 422L, 583L, 728L, 242L, 691L, 155L, 170L, 704L,
185L, 685L, 737L, 401L, 545L, 390L, 499L, 10L, 30L, 532L, 591L,
684L, 590L, 745L, 56L, 615L, 701L, 836L, 841L, 356L, 489L, 710L,
747L, 849L, 122L, 328L, 602L, 865L, 839L, 178L, 908L, 504L, 618L,
635L, 6L, 138L, 154L, 225L, 479L, 748L, 14L, 293L, 310L, 440L,
698L, 89L, 151L, 157L, 99L, 158L, 342L, 454L, 582L, 832L, 156L,
781L, 37L, 307L, 353L, 579L, 733L, 67L, 281L, 383L, 556L, 734L,
791L, 898L, 27L, 111L, 232L, 268L, 395L, 18L, 106L, 126L, 180L,
261L, 337L, 453L, 641L, 675L, 793L, 819L, 214L, 221L, 393L, 462L,
474L, 611L, 744L, 750L, 845L, 32L, 45L, 78L, 160L, 163L, 197L,
334L, 340L, 355L, 368L, 388L, 408L, 417L, 531L, 581L, 606L, 651L,
754L, 787L, 797L, 816L, 853L, 893L, 23L, 50L, 52L, 80L, 186L,
213L, 248L, 279L, 397L, 400L, 428L, 434L, 435L, 478L, 543L, 555L,
573L, 628L, 688L, 731L, 806L, 868L, 894L, 904L, 61L, 71L, 88L,
92L, 174L, 194L, 230L, 236L, 256L, 265L, 300L, 317L, 322L, 348L,
349L, 366L, 377L, 380L, 386L, 418L, 448L, 451L, 487L, 608L, 624L,
643L, 678L, 711L, 746L, 786L, 794L, 801L, 834L, 852L, 895L, 912L,
15L, 42L, 51L, 74L, 90L, 95L, 105L, 137L, 142L, 145L, 167L, 177L,
179L, 181L, 196L, 233L, 235L, 240L, 246L, 259L, 276L, 288L, 289L,
299L, 302L, 311L, 316L, 327L, 330L, 333L, 343L, 344L, 346L, 369L,
419L, 420L, 431L, 447L, 455L, 464L, 466L, 473L, 481L, 485L, 490L,
494L, 508L, 515L, 526L, 540L, 542L, 549L, 609L, 617L, 622L, 631L,
652L, 667L, 681L, 687L, 690L, 692L, 694L, 716L, 727L, 758L, 767L,
768L, 776L, 780L, 792L, 796L, 811L, 823L, 835L, 838L, 850L, 870L,
907L, 910L, 1L, 2L, 7L, 11L, 13L, 31L, 38L, 40L, 58L, 62L, 66L,
68L, 72L, 73L, 87L, 93L, 96L, 101L, 109L, 119L, 120L, 125L, 128L,
132L, 141L, 143L, 150L, 164L, 166L, 173L, 176L, 182L, 187L, 188L,
206L, 208L, 209L, 212L, 219L, 239L, 245L, 247L, 249L, 258L, 266L,
267L, 269L, 271L, 273L, 274L, 280L, 287L, 304L, 308L, 313L, 318L,
321L, 325L, 326L, 335L, 336L, 358L, 387L, 389L, 405L, 406L, 415L,
421L, 427L, 433L, 436L, 442L, 443L, 445L, 449L, 456L, 463L, 470L,
471L, 486L, 493L, 495L, 510L, 517L, 518L, 522L, 553L, 554L, 561L,
567L, 570L, 574L, 576L, 578L, 580L, 594L, 600L, 616L, 630L, 636L,
659L, 663L, 673L, 679L, 680L, 696L, 699L, 700L, 706L, 707L, 709L,
721L, 724L, 725L, 741L, 761L, 762L, 764L, 769L, 772L, 775L, 777L,
784L, 795L, 799L, 800L, 805L, 818L, 821L, 822L, 828L, 833L, 843L,
844L, 854L, 859L, 862L, 863L, 864L, 866L, 873L, 875L, 880L, 882L,
883L, 885L, 888L, 892L, 896L, 902L, 905L, 913L, 3L, 4L, 5L, 8L,
9L, 12L, 16L, 17L, 19L, 20L, 21L, 22L, 24L, 25L, 26L, 28L, 29L,
33L, 34L, 35L, 36L, 39L, 41L, 43L, 44L, 47L, 48L, 49L, 53L, 55L,
59L, 60L, 63L, 64L, 65L, 69L, 70L, 75L, 76L, 77L, 79L, 81L, 82L,
83L, 84L, 85L, 86L, 91L, 94L, 97L, 98L, 100L, 102L, 107L, 108L,
110L, 112L, 113L, 115L, 116L, 117L, 118L, 121L, 123L, 124L, 127L,
129L, 130L, 131L, 133L, 134L, 135L, 136L, 139L, 140L, 144L, 146L,
147L, 148L, 149L, 152L, 153L, 161L, 165L, 168L, 169L, 171L, 172L,
175L, 183L, 184L, 189L, 190L, 191L, 192L, 193L, 195L, 198L, 199L,
200L, 201L, 202L, 203L, 204L, 205L, 210L, 211L, 215L, 216L, 217L,
218L, 220L, 222L, 224L, 227L, 228L, 229L, 231L, 234L, 237L, 238L,
241L, 243L, 244L, 250L, 251L, 252L, 253L, 254L, 255L, 257L, 260L,
262L, 263L, 264L, 270L, 272L, 275L, 277L, 278L, 282L, 283L, 284L,
285L, 286L, 290L, 291L, 292L, 294L, 295L, 296L, 297L, 298L, 301L,
303L, 305L, 306L, 309L, 312L, 314L, 315L, 319L, 320L, 323L, 324L,
329L, 331L, 332L, 338L, 339L, 341L, 345L, 347L, 350L, 351L, 352L,
354L, 357L, 359L, 360L, 361L, 362L, 363L, 364L, 365L, 367L, 370L,
371L, 372L, 373L, 374L, 375L, 376L, 379L, 381L, 382L, 384L, 385L,
391L, 392L, 394L, 396L, 398L, 399L, 402L, 403L, 404L, 407L, 409L,
410L, 411L, 412L, 413L, 414L, 416L, 423L, 424L, 425L, 426L, 429L,
430L, 432L, 437L, 438L, 439L, 441L, 444L, 446L, 450L, 452L, 457L,
458L, 460L, 461L, 465L, 467L, 468L, 469L, 472L, 475L, 476L, 477L,
480L, 482L, 483L, 484L, 491L, 492L, 496L, 497L, 498L, 500L, 501L,
502L, 503L, 505L, 506L, 507L, 509L, 511L, 512L, 513L, 514L, 516L,
519L, 520L, 521L, 523L, 524L, 525L, 527L, 528L, 529L, 530L, 533L,
534L, 535L, 536L, 537L, 538L, 541L, 544L, 546L, 548L, 550L, 551L,
552L, 557L, 558L, 559L, 560L, 562L, 563L, 564L, 565L, 566L, 568L,
569L, 571L, 572L, 575L, 577L, 584L, 585L, 586L, 587L, 588L, 589L,
592L, 593L, 595L, 596L, 598L, 599L, 601L, 603L, 604L, 605L, 607L,
610L, 612L, 613L, 614L, 619L, 620L, 621L, 625L, 626L, 627L, 629L,
632L, 633L, 634L, 637L, 638L, 639L, 640L, 642L, 644L, 645L, 646L,
647L, 648L, 649L, 650L, 653L, 656L, 657L, 658L, 660L, 662L, 664L,
665L, 666L, 668L, 669L, 670L, 671L, 672L, 674L, 677L, 682L, 683L,
686L, 689L, 693L, 695L, 697L, 702L, 703L, 705L, 708L, 712L, 713L,
714L, 715L, 717L, 718L, 719L, 720L, 723L, 726L, 729L, 730L, 732L,
736L, 739L, 740L, 749L, 751L, 752L, 753L, 755L, 757L, 759L, 760L,
763L, 765L, 766L, 770L, 771L, 773L, 774L, 778L, 779L, 782L, 783L,
785L, 788L, 789L, 790L, 798L, 802L, 803L, 804L, 807L, 808L, 809L,
810L, 812L, 813L, 814L, 815L, 817L, 824L, 825L, 826L, 827L, 829L,
830L, 831L, 837L, 840L, 842L, 846L, 847L, 848L, 851L, 855L, 856L,
857L, 858L, 860L, 861L, 867L, 869L, 871L, 872L, 874L, 876L, 877L,
879L, 881L, 884L, 886L, 887L, 889L, 890L, 891L, 897L, 899L, 900L,
901L, 903L, 906L, 909L, 911L, 914L, 915L, 916L, 917L), class = "data.frame")
EDIT: The provided ranks should be disregarded, as ties.methods = "average" is the wrong method to use in this case.
I reckon that the top x% categories are defined by the rank, so that the top x% categories is the categories with a rank lower than max(rank)*x/100. Then it's actually quite easy to do.
You calculate cumulative proportions from the counts and convert the ranks to a percentage of the total categories as well,
You add these to together and check which one is the closest to 1
In R code this could be done like this :
get_cutoff <- function(rank, freq){
counts <- tapply(freq, rank, sum, na.rm = TRUE)
ranks <- as.numeric(names(counts))
pdiff <- cumsum(counts / sum(counts)) + ranks/max(ranks) - 1
pos <- which.min(abs(pdiff))
return(ranks[pos]/max(ranks))
}
Storing your structure in a data frame called mydf gives the following:
get_cutoff(mydf$rank, mydf$Freq)
[1] 0.08833152
To check for yourself this is correct, you can do:
> counts <- with(mydf, tapply(Freq, rank, sum, na.rm = TRUE))
> ranks <- as.numeric(names(counts))
> get_cutoff(mydf$rank, mydf$Freq) * max(ranks)
[1] 81
> which(ranks == 81)
[1] 57
> sum(counts[1:57])/sum(counts)
[1] 0.915586
> sum(counts[1:57])/sum(counts) + 81/max(ranks)
[1] 1.003918
Due to the discrete nature of ranks, only in specific cases this will be a 100% perfect solution. The algorithm above finds the fraction tied to the rank that gives you the result closest to the perfect solution.
Based on the very nice solution by #JorysMeys, here is a leaner solution, which only requires the frequency distribution as an input and which returns the matching share of observations in addition to the cutoff (because the sum will seldom be 100%).
get_cutoff <- function(freq){
# remove NA values from distribution (make sure NA doesn't mean zero before running the function)
freq <- freq[!is.na(freq)]
# order distribution by decreasing frequency
freq <- freq[order(-freq)]
# subtract 100% from cumulative frequency share plus rank share
pdiff <- cumsum(freq/sum(freq)) + seq(1,length(freq))/length(freq) - 1
# position (=rank) of smallest absolute difference (generally not 0 since ranks are discrete)
pos <- which.min(abs(pdiff))
# return cutoff of rank share and matching cumulative frequency share
return(c(pos/length(freq), sum(freq[1:pos])/sum(freq)))
}
The reason why there is no need to calculate rank beforehand is that the cutoff should not depend on the ties.method argument of rank(). If you do calculate rank beforehand and apply the other solution, then you should use ties.method = "random". Other methods will give uninterpretable results. This solution calculates a simple rank with seq(1,length(freq)), which is strictly equivalent to ties.method = "random".