This question already has answers here:
replace NA with groups mean in a non specified number of columns [duplicate]
(2 answers)
Closed 3 years ago.
I have been trying various time series imputation models to impute the missing time series using the imputeTS but the test results are quite poor. Since it looks like seasonal time series data I thought about simply imputing the missing values with the median or average over a number of months.
The data looks like:
> head(data, 10)
v1 v2 v3 v4
1 1908 1 118 10
2 1908 2 138 33
3 1908 3 128 17
4 1908 4 NA 60
5 1908 5 NA 114
6 1908 6 72 124
7 1908 7 NA 44
8 1908 8 70 134
9 1908 9 58 121
10 1908 10 42 117
I calculated the median values:
data %>%
as_tibble() %>%
group_by(v2) %>%
summarise(imp_v3 = median(v3, na.rm = TRUE),
imp_v4 = median(v4, na.rm = TRUE))
Which gives:
# A tibble: 12 x 3
v2 imp_v3 imp_v4
<int> <dbl> <dbl>
1 1 126 23
2 2 132 27.5
3 3 138 33
4 4 22.5 76
5 5 42.5 102.
6 6 72 127
7 7 82 50
8 8 80 51
9 9 57 121
10 10 24 98
11 11 145 71
12 12 130. 31
All I want to do now is impute the missing values for each v1 and v2 with the corresponding medians.
That is all missing values in v3 which has a 1 in v2 will be replaced with 126. All missing values in v4 which has a 5 in column v2 would be replaced with 102..
The numbers in v1 are years and the numbers in v2 are months.
Data:
data <- structure(list(v1 = c(1908L, 1908L, 1908L, 1908L, 1908L, 1908L,
1908L, 1908L, 1908L, 1908L, 1908L, 1908L, 1909L, 1909L, 1909L,
1909L, 1909L, 1909L, 1909L, 1909L, 1909L, 1909L, 1909L, 1909L,
1910L, 1910L, 1910L, 1910L, 1910L, 1910L, 1910L, 1910L, 1910L,
1910L, 1910L, 1910L, 1911L, 1911L, 1911L, 1911L, 1911L, 1911L,
1911L, 1911L, 1911L, 1911L, 1911L, 1911L, 1912L, 1912L, 1912L,
1912L, 1912L, 1912L, 1912L, 1912L, 1912L, 1912L, 1912L, 1912L,
1913L, 1913L, 1913L, 1913L, 1913L, 1913L, 1913L, 1913L, 1913L,
1913L, 1913L, 1913L, 1914L, 1914L, 1914L, 1914L, 1914L, 1914L,
1914L, 1914L, 1914L, 1914L, 1914L, 1914L, 1915L, 1915L, 1915L,
1915L, 1915L, 1915L, 1915L, 1915L, 1915L, 1915L, 1915L, 1915L,
1916L, 1916L, 1916L, 1916L, 1916L, 1916L, 1916L, 1916L, 1916L,
1916L, 1916L, 1916L, 1917L, 1917L, 1917L, 1917L, 1917L, 1917L,
1917L, 1917L, 1917L, 1917L, 1917L, 1917L, 1918L, 1918L, 1918L,
1918L, 1918L, 1918L, 1918L, 1918L, 1918L, 1918L, 1918L, 1918L,
1919L, 1919L, 1919L, 1919L, 1919L, 1919L, 1919L, 1919L, 1919L,
1919L, 1919L, 1919L, 1920L, 1920L, 1920L, 1920L, 1920L, 1920L,
1920L, 1920L, 1920L, 1920L, 1920L, 1920L, 1921L, 1921L, 1921L,
1921L, 1921L, 1921L, 1921L, 1921L, 1921L, 1921L, 1921L, 1921L,
1922L, 1922L, 1922L, 1922L, 1922L, 1922L, 1922L, 1922L, 1922L,
1922L, 1922L, 1922L, 1923L, 1923L, 1923L, 1923L, 1923L, 1923L,
1923L, 1923L, 1923L, 1923L, 1923L, 1923L, 1924L, 1924L, 1924L,
1924L, 1924L, 1924L, 1924L, 1924L, 1924L, 1924L, 1924L, 1924L,
1925L, 1925L, 1925L, 1925L, 1925L, 1925L, 1925L, 1925L, 1925L,
1925L, 1925L, 1925L, 1926L, 1926L, 1926L, 1926L, 1926L, 1926L,
1926L, 1926L, 1926L, 1926L, 1926L, 1926L, 1927L, 1927L, 1927L,
1927L, 1927L, 1927L, 1927L, 1927L, 1927L, 1927L, 1927L, 1927L,
1928L, 1928L, 1928L, 1928L, 1928L, 1928L, 1928L, 1928L, 1928L,
1928L, 1928L, 1928L, 1929L, 1929L, 1929L, 1930L, 1930L, 1930L,
1930L, 1930L, 1930L, 1930L, 1930L, 1930L, 1930L, 1930L, 1930L,
1931L, 1931L, 1931L, 1931L, 1931L, 1931L, 1931L, 1931L, 1931L,
1931L, 1931L, 1931L, 1932L, 1932L, 1932L, 1932L, 1932L, 1932L,
1932L, 1932L, 1932L, 1932L, 1932L, 1932L, 1933L, 1933L, 1933L,
1933L, 1933L, 1933L, 1933L, 1933L, 1933L, 1933L, 1933L, 1933L,
1934L, 1934L, 1934L, 1934L, 1934L, 1934L, 1934L, 1934L, 1934L,
1934L, 1934L, 1934L, 1935L, 1935L, 1935L, 1935L, 1935L, 1935L,
1935L, 1935L, 1935L, 1935L, 1935L, 1935L, 1936L, 1936L, 1936L,
1936L, 1936L, 1936L, 1936L, 1936L, 1936L, 1936L, 1936L, 1936L,
1937L, 1937L, 1937L, 1937L, 1937L, 1937L, 1937L, 1937L, 1937L,
1937L, 1937L, 1937L, 1938L, 1938L, 1938L, 1938L, 1938L, 1938L,
1938L, 1938L, 1938L, 1938L, 1938L, 1938L, 1939L, 1939L, 1939L,
1939L, 1939L, 1939L, 1939L, 1939L, 1939L, 1939L, 1939L, 1939L,
1940L, 1940L, 1940L, 1940L, 1940L, 1940L, 1940L, 1940L, 1940L,
1940L, 1940L, 1940L, 1941L, 1941L, 1941L, 1941L, 1941L, 1941L,
1941L, 1941L, 1941L, 1941L, 1941L, 1941L, 1942L, 1942L, 1942L,
1942L, 1942L, 1942L, 1942L, 1942L, 1942L, 1942L, 1942L, 1942L,
1943L, 1943L, 1943L, 1943L, 1943L, 1943L, 1943L, 1943L, 1943L,
1943L, 1943L, 1943L, 1944L, 1944L, 1944L, 1944L, 1944L, 1944L,
1944L, 1944L, 1944L, 1944L, 1944L, 1944L, 1945L, 1945L, 1945L,
1945L, 1945L, 1945L, 1945L, 1945L), v2 = c(1L, 2L, 3L, 4L, 5L,
6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L,
9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L,
12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L,
3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L,
6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L,
9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L,
12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L,
3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L,
6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L,
9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L,
12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L,
3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L,
6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L,
9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L,
12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L,
3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L,
6L, 7L, 8L, 9L, 10L, 11L, 12L, 10L, 11L, 12L, 1L, 2L, 3L, 4L,
5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L,
11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L,
1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L, 3L,
4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L,
7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L,
10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L,
12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L,
3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L,
6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L,
9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L,
12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L,
3L, 4L, 5L, 6L, 7L, 8L), v3 = c(118L, 138L, 128L, NA, NA, 72L,
NA, 70L, 58L, 42L, 159L, 125L, 118L, 122L, 123L, 22L, 43L, 45L,
68L, 82L, 41L, 29L, 140L, 120L, 119L, NA, 156L, 161L, 39L, 72L,
65L, 75L, 45L, 26L, 122L, 145L, 125L, 135L, 130L, 3L, 58L, 73L,
103L, 101L, 68L, 16L, 144L, 147L, NA, 132L, NA, 24L, NA, NA,
77L, 46L, 34L, 18L, 148L, 154L, 121L, NA, 148L, 9L, 43L, 69L,
70L, 79L, 64L, 27L, 4L, 134L, 126L, 158L, NA, 37L, 34L, 78L,
86L, 91L, 65L, NA, 156L, 130L, 121L, 129L, 144L, 12L, 36L, 80L,
NA, 77L, 63L, NA, 125L, NA, 160L, 121L, 112L, 16L, 44L, 40L,
NA, 96L, NA, NA, 153L, 112L, 105L, 107L, 122L, 148L, 58L, NA,
92L, 76L, 68L, 5L, 159L, 113L, 127L, 145L, 147L, NA, 64L, 61L,
NA, NA, NA, 20L, 144L, 153L, NA, 106L, 121L, 4L, 68L, 72L, 67L,
83L, NA, 14L, 117L, 137L, 139L, 148L, 4L, 160L, 44L, 70L, 58L,
59L, 54L, 27L, 152L, 128L, 154L, 130L, 162L, 17L, 47L, 80L, 104L,
NA, 72L, 57L, 127L, 155L, 116L, 127L, 129L, 151L, 59L, 65L, NA,
56L, 44L, NA, 153L, 140L, 147L, 128L, 155L, 161L, 17L, NA, 95L,
70L, 47L, 18L, 122L, NA, 126L, 119L, 132L, 160L, 35L, 62L, 75L,
62L, NA, 24L, 154L, 155L, 138L, 134L, 138L, 6L, 42L, 83L, 98L,
82L, 39L, 30L, 125L, 114L, 133L, 147L, 150L, 23L, NA, 67L, 97L,
87L, 66L, 8L, 142L, 130L, 133L, 132L, 158L, 5L, 36L, NA, 81L,
74L, 45L, 31L, 145L, NA, NA, 142L, 143L, 14L, 36L, 49L, 82L,
80L, 54L, 24L, 161L, 124L, 21L, NA, 137L, 141L, 109L, NA, 162L,
34L, 81L, 70L, 80L, 52L, 26L, 150L, 126L, 122L, 119L, 130L, NA,
41L, 62L, 75L, NA, 39L, 22L, 158L, 138L, 153L, 125L, 141L, 158L,
28L, 73L, 84L, 90L, 54L, 16L, 147L, 138L, 112L, NA, 4L, 23L,
51L, 89L, 100L, 99L, 83L, 23L, 141L, 111L, 138L, 136L, 138L,
10L, 48L, 77L, 104L, 80L, 79L, 26L, NA, 157L, 131L, 140L, 154L,
10L, 33L, 81L, 99L, NA, 60L, 20L, 152L, 113L, 118L, 110L, 153L,
NA, 41L, 76L, 78L, 88L, 66L, 25L, 144L, 142L, 135L, 134L, 118L,
16L, 50L, 66L, 90L, NA, 59L, 28L, 142L, 113L, 143L, 133L, 25L,
15L, 38L, 69L, 74L, 87L, 61L, 24L, 11L, 127L, 121L, 141L, 144L,
NA, 45L, 76L, 78L, 87L, 62L, 12L, 3L, 119L, 1L, NA, 154L, 7L,
64L, 102L, 78L, 79L, 53L, 19L, 151L, 126L, 2L, 115L, NA, 146L,
23L, 85L, 103L, 74L, 71L, NA, 151L, 140L, 94L, 93L, 136L, 22L,
40L, 79L, 82L, 85L, 56L, 28L, 141L, 152L, NA, 150L, 162L, 35L,
56L, 72L, 92L, 75L, 51L, 31L, 149L, 126L, 147L, NA, 146L, 26L,
40L, 55L, 82L, 88L, 47L, 13L, 149L, 131L, 108L, 159L, 17L, 32L,
49L, 72L, 95L, 83L), v4 = c(10L, 33L, 17L, 60L, 114L, 124L, 44L,
134L, 121L, 117L, 73L, NA, 15L, 3L, 3L, 72L, 86L, 112L, 42L,
41L, 118L, 106L, 31L, 18L, 5L, 29L, NA, 63L, NA, 133L, 135L,
52L, 122L, 110L, 4L, 75L, NA, 27L, 33L, 78L, 116L, 127L, 51L,
NA, 123L, 94L, 71L, 72L, 15L, NA, 74L, 73L, 103L, 136L, 51L,
129L, 114L, 81L, NA, 63L, 25L, 26L, 60L, 77L, 105L, 132L, 38L,
NA, 37L, NA, 89L, 62L, 21L, 74L, 65L, 82L, 96L, 128L, 49L, 45L,
121L, 109L, NA, 31L, 27L, 22L, 29L, 74L, 87L, 119L, 37L, 36L,
126L, 89L, 6L, 26L, 82L, 19L, NA, 70L, 100L, 114L, 45L, 54L,
126L, 98L, 80L, 6L, 5L, 12L, NA, 22L, 103L, 131L, 44L, 53L, 37L,
75L, NA, 1L, 16L, 68L, 59L, 68L, 110L, NA, 39L, 48L, 118L, 98L,
31L, 76L, 15L, 10L, NA, NA, 110L, 131L, NA, 39L, 120L, 70L, 16L,
59L, NA, NA, 70L, 79L, 107L, 127L, 38L, 134L, 122L, 105L, 83L,
31L, 77L, 33L, NA, NA, 96L, 123L, 53L, 49L, 130L, 125L, 23L,
72L, NA, 19L, 27L, 21L, NA, 123L, 133L, 136L, 121L, 87L, 72L,
72L, 69L, 33L, 67L, 71L, 85L, 120L, NA, 41L, NA, 102L, 19L, 19L,
25L, NA, 9L, NA, 107L, 131L, 43L, 34L, 36L, 104L, 83L, 86L, 61L,
28L, 32L, 73L, 109L, 129L, 54L, 51L, 112L, 101L, 2L, 8L, 29L,
74L, 70L, 87L, 84L, 120L, NA, 44L, NA, 80L, 61L, 30L, 33L, 20L,
74L, 77L, 93L, 111L, 50L, 51L, 129L, 102L, 67L, 5L, 23L, 62L,
62L, 72L, 94L, 115L, 47L, 44L, 122L, 98L, 86L, 1L, 90L, 64L,
63L, 27L, 5L, 24L, 81L, 95L, 133L, NA, NA, 136L, 107L, NA, 29L,
14L, 24L, 7L, 77L, 105L, 135L, 52L, 136L, 120L, 84L, 88L, 63L,
70L, 18L, 26L, 63L, NA, 125L, 56L, 56L, 124L, 85L, NA, 75L, 3L,
24L, 60L, 86L, 114L, 136L, 56L, 57L, NA, NA, 71L, 1L, 29L, 29L,
25L, 78L, 102L, 132L, 58L, 41L, 34L, 111L, 76L, 90L, 33L, 66L,
72L, 78L, 86L, 37L, 52L, 48L, 129L, 98L, NA, NA, 19L, 9L, 71L,
60L, 101L, 133L, 50L, NA, 46L, 96L, NA, 59L, 31L, 30L, 6L, 88L,
113L, NA, 56L, 51L, 126L, 107L, 61L, 17L, NA, 62L, 91L, 74L,
100L, 35L, 43L, 52L, 134L, 108L, 97L, 26L, 23L, 63L, 66L, 80L,
NA, 125L, 49L, 56L, 40L, 86L, 88L, 28L, 13L, 11L, 33L, 75L, 109L,
40L, 43L, 39L, 119L, 99L, 80L, 29L, 12L, NA, 23L, 65L, NA, 130L,
57L, NA, 46L, 109L, 69L, 66L, 10L, NA, 20L, 78L, 97L, 126L, 43L,
58L, 120L, 107L, 66L, 76L, 23L, 69L, 64L, 98L, 96L, 135L, 41L,
47L, 127L, 97L, 74L, 26L, 65L, 20L, 27L, 92L, 98L, 124L, 55L,
53L, 121L, 96L, NA, 27L, NA, 73L, NA, 85L, 106L, 135L, 54L, NA
)), class = "data.frame", row.names = c(NA, -443L))
We can use replace to replace the NA elements with the median of the column
library(dplyr)
data %>%
group_by(v2) %>%
mutate_at(vars(v3, v4), list(~ replace(., is.na(.), median(., na.rm = TRUE))))
# A tibble: 443 x 4
# Groups: v2 [12]
# v1 v2 v3 v4
# <int> <int> <dbl> <dbl>
# 1 1908 1 118 10
# 2 1908 2 138 33
# 3 1908 3 128 17
# 4 1908 4 22.5 60
# 5 1908 5 42.5 114
# 6 1908 6 72 124
# 7 1908 7 82 44
# 8 1908 8 70 134
# 9 1908 9 58 121
#10 1908 10 42 117
# … with 433 more rows
Or another option is na.aggregate from zoo
library(zoo)
data %>%
group_by(v2) %>%
mutate_at(vars(v3, v4), na.aggregate)
By default, the FUN is mean. If we want median specify the FUN
data %>%
group_by(v2) %>%
mutate_at(vars(v3, v4), na.aggregate, FUN = median)
Related
I have a data.frame fish.test0 for which I want to grep specific variables (in varlist) matching the group column to create a sub-data.frame that will undergo a statistical test. The results of the test is saved in tests.res.t. I want to loop the varlist so that I get one results for each input in varlist
Script:
varlist <- c("Abiotrophia","Alphatorquevirus")
for (i in varlist) {
fish.test <- fish.test0[grep("i",fish.test0$group),]
column <- c("ACDC")
tests <- list()
dat_test <- sapply( column, function(colx)
lapply( unique(fish.test$Merge), function(x)
fisher.test( data.frame(
a=c(( fish.test[ which(fish.test$Merge %in% x)[2],"Present"] -
fish.test[ which(fish.test$Merge %in% x)[2], colx] ),fish.test[ which(fish.test$Merge %in% x)[2], colx]
),
b=c(( fish.test[ which(fish.test$Merge %in% x)[1],"NotPresent"] -
fish.test[ which(fish.test$Merge %in% x)[1], colx] ), fish.test[ which(fish.test$Merge %in% x)[1], colx]))) #,alternative = "greater"
) )
rownames(dat_test) <- unique(fish.test$Merge )
colnames(dat_test) <- column
tests.res <- sapply(dat_test[1:dim(dat_test)[1],1], function(x) {
c(x$estimate[1],
x$estimate[2],
ci.lower = x$conf.int[1],
ci.upper = x$conf.int[2],
p.value = x$p.value)
})
tests.res.t <- as.data.frame(t(tests.res))
}
test-data:
fish.test0 <- structure(list(Present = c(4L, 4L, 9L, 9L, 57L, 57L, 146L, 146L,
91L, 91L, 26L, 26L, 6L, 6L, 12L, 12L, 33L, 33L, 10L, 10L, 66L,
66L, 4L, 4L, 4L, 4L, 9L, 9L, 18L, 18L, 19L, 19L, 51L, 51L, 50L,
50L, 12L, 12L, 7L, 7L, 14L, 14L, 27L, 27L, 9L, 9L, 5L, 5L, 6L,
6L, 22L, 22L, 3L, 3L, 14L, 14L, 4L, 4L, 15L, 15L, 6L, 6L, 8L,
8L, 4L, 4L), NotPresent = c(11L, 11L, 44L, 44L, 126L, 126L, 532L,
532L, 382L, 382L, 97L, 97L, 14L, 14L, 43L, 43L, 85L, 85L, 41L,
41L, 336L, 336L, 19L, 19L, 27L, 27L, 67L, 67L, 108L, 108L, 81L,
81L, 240L, 240L, 258L, 258L, 47L, 47L, 31L, 31L, 82L, 82L, 110L,
110L, 63L, 63L, 178L, 178L, 672L, 672L, 451L, 451L, 120L, 120L,
104L, 104L, 47L, 47L, 387L, 387L, 94L, 94L, 300L, 300L, 133L,
133L), group = c("G__Abiotrophia_NotPresent_Anus", "G__Abiotrophia_Present_Anus",
"G__Abiotrophia_NotPresent_Bile duct", "G__Abiotrophia_Present_Bile duct",
"G__Abiotrophia_NotPresent_Bone/Soft tissue", "G__Abiotrophia_Present_Bone/Soft tissue",
"G__Abiotrophia_NotPresent_Breast", "G__Abiotrophia_Present_Breast",
"G__Abiotrophia_NotPresent_Colorectum", "G__Abiotrophia_Present_Colorectum",
"G__Abiotrophia_NotPresent_Esophagus", "G__Abiotrophia_Present_Esophagus",
"G__Abiotrophia_NotPresent_Gallbladder", "G__Abiotrophia_Present_Gallbladder",
"G__Abiotrophia_NotPresent_Head and neck", "G__Abiotrophia_Present_Head and neck",
"G__Abiotrophia_NotPresent_Kidney", "G__Abiotrophia_Present_Kidney",
"G__Abiotrophia_NotPresent_Liver", "G__Abiotrophia_Present_Liver",
"G__Abiotrophia_NotPresent_Lung", "G__Abiotrophia_Present_Lung",
"G__Abiotrophia_NotPresent_Lymphoid tissue", "G__Abiotrophia_Present_Lymphoid tissue",
"G__Abiotrophia_NotPresent_Mesothelium", "G__Abiotrophia_Present_Mesothelium",
"G__Abiotrophia_NotPresent_Nervous system", "G__Abiotrophia_Present_Nervous system",
"G__Abiotrophia_NotPresent_Ovary", "G__Abiotrophia_Present_Ovary",
"G__Abiotrophia_NotPresent_Pancreas", "G__Abiotrophia_Present_Pancreas",
"G__Abiotrophia_NotPresent_Prostate", "G__Abiotrophia_Present_Prostate",
"G__Abiotrophia_NotPresent_Skin", "G__Abiotrophia_Present_Skin",
"G__Abiotrophia_NotPresent_Small intestine", "G__Abiotrophia_Present_Small intestine",
"G__Abiotrophia_NotPresent_Stomach", "G__Abiotrophia_Present_Stomach",
"G__Abiotrophia_NotPresent_Unknown", "G__Abiotrophia_Present_Unknown",
"G__Abiotrophia_NotPresent_Urothelial tract", "G__Abiotrophia_Present_Urothelial tract",
"G__Abiotrophia_NotPresent_Uterus", "G__Abiotrophia_Present_Uterus",
"G__Alphatorquevirus_NotPresent_Bone/Soft tissue", "G__Alphatorquevirus_Present_Bone/Soft tissue",
"G__Alphatorquevirus_NotPresent_Breast", "G__Alphatorquevirus_Present_Breast",
"G__Alphatorquevirus_NotPresent_Colorectum", "G__Alphatorquevirus_Present_Colorectum",
"G__Alphatorquevirus_NotPresent_Esophagus", "G__Alphatorquevirus_Present_Esophagus",
"G__Alphatorquevirus_NotPresent_Kidney", "G__Alphatorquevirus_Present_Kidney",
"G__Alphatorquevirus_NotPresent_Liver", "G__Alphatorquevirus_Present_Liver",
"G__Alphatorquevirus_NotPresent_Lung", "G__Alphatorquevirus_Present_Lung",
"G__Alphatorquevirus_NotPresent_Pancreas", "G__Alphatorquevirus_Present_Pancreas",
"G__Alphatorquevirus_NotPresent_Skin", "G__Alphatorquevirus_Present_Skin",
"G__Alphatorquevirus_NotPresent_Urothelial tract", "G__Alphatorquevirus_Present_Urothelial tract"
), ABCD = c(3L, 2L, 17L, 6L, 34L, 18L, 240L, 53L, 321L, 73L,
87L, 25L, 6L, 3L, 20L, 8L, 15L, 7L, 19L, 4L, 265L, 42L, 6L, 1L,
4L, 2L, 22L, 4L, 70L, 13L, 54L, 12L, 116L, 33L, 58L, 11L, 6L,
2L, 26L, 6L, 42L, 8L, 74L, 18L, 19L, 3L, 52L, 0L, 288L, 5L, 377L,
17L, 110L, 2L, 19L, 3L, 21L, 2L, 298L, 9L, 60L, 6L, 68L, 1L,
89L, 3L), Total = c(15L, 15L, 53L, 53L, 183L, 183L, 678L, 678L,
473L, 473L, 123L, 123L, 20L, 20L, 55L, 55L, 118L, 118L, 51L,
51L, 402L, 402L, 23L, 23L, 31L, 31L, 76L, 76L, 126L, 126L, 100L,
100L, 291L, 291L, 308L, 308L, 59L, 59L, 38L, 38L, 96L, 96L, 137L,
137L, 72L, 72L, 183L, 183L, 678L, 678L, 473L, 473L, 123L, 123L,
118L, 118L, 51L, 51L, 402L, 402L, 100L, 100L, 308L, 308L, 137L,
137L), Merge = c("Abiotrophia_Anus", "Abiotrophia_Anus", "Abiotrophia_Bile duct",
"Abiotrophia_Bile duct", "Abiotrophia_Bone/Soft tissue", "Abiotrophia_Bone/Soft tissue",
"Abiotrophia_Breast", "Abiotrophia_Breast", "Abiotrophia_Colorectum",
"Abiotrophia_Colorectum", "Abiotrophia_Esophagus", "Abiotrophia_Esophagus",
"Abiotrophia_Gallbladder", "Abiotrophia_Gallbladder", "Abiotrophia_Head and neck",
"Abiotrophia_Head and neck", "Abiotrophia_Kidney", "Abiotrophia_Kidney",
"Abiotrophia_Liver", "Abiotrophia_Liver", "Abiotrophia_Lung",
"Abiotrophia_Lung", "Abiotrophia_Lymphoid tissue", "Abiotrophia_Lymphoid tissue",
"Abiotrophia_Mesothelium", "Abiotrophia_Mesothelium", "Abiotrophia_Nervous system",
"Abiotrophia_Nervous system", "Abiotrophia_Ovary", "Abiotrophia_Ovary",
"Abiotrophia_Pancreas", "Abiotrophia_Pancreas", "Abiotrophia_Prostate",
"Abiotrophia_Prostate", "Abiotrophia_Skin", "Abiotrophia_Skin",
"Abiotrophia_Small intestine", "Abiotrophia_Small intestine",
"Abiotrophia_Stomach", "Abiotrophia_Stomach", "Abiotrophia_Unknown",
"Abiotrophia_Unknown", "Abiotrophia_Urothelial tract", "Abiotrophia_Urothelial tract",
"Abiotrophia_Uterus", "Abiotrophia_Uterus", "Alphatorquevirus_Bone/Soft tissue",
"Alphatorquevirus_Bone/Soft tissue", "Alphatorquevirus_Breast",
"Alphatorquevirus_Breast", "Alphatorquevirus_Colorectum", "Alphatorquevirus_Colorectum",
"Alphatorquevirus_Esophagus", "Alphatorquevirus_Esophagus", "Alphatorquevirus_Kidney",
"Alphatorquevirus_Kidney", "Alphatorquevirus_Liver", "Alphatorquevirus_Liver",
"Alphatorquevirus_Lung", "Alphatorquevirus_Lung", "Alphatorquevirus_Pancreas",
"Alphatorquevirus_Pancreas", "Alphatorquevirus_Skin", "Alphatorquevirus_Skin",
"Alphatorquevirus_Urothelial tract", "Alphatorquevirus_Urothelial tract"
)), row.names = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 10L, 9L, 12L,
11L, 13L, 14L, 16L, 15L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L,
25L, 26L, 28L, 27L, 29L, 30L, 31L, 32L, 34L, 33L, 35L, 36L, 38L,
37L, 40L, 39L, 42L, 43L, 45L, 44L, 47L, 46L, 1011L, 1012L, 1014L,
1013L, 1015L, 1016L, 1017L, 1018L, 1019L, 1020L, 1022L, 1021L,
1023L, 1024L, 1026L, 1025L, 1027L, 1028L, 1029L, 1030L), class = "data.frame")
This is probably not an answer but it should help to improve you code. If I'm terribly wrong, I'll remove my answer right away. I have loeft out the test business which I don't understand, but your problem seems to be extraction.
The first thing is that you need to remove the quotation marks in your grep command, try:
varlist <- c("Abiotrophia","Alphatorquevirus")
for( i in varlist )
{
# extract rows which contain the variable
fish.test <- fish.test0[ grep( i, fish.test0$group ), ]
print( head( fish.test ) )
}
From what I understand, you need to define column and tests outside your loop. Does that give you more of what you want:
varlist <- c("Abiotrophia","Alphatorquevirus")
column <- "ACDC"
tests <- list()
for( i in 1 : length( varlist ) ) # index can be used later to fill the list
{
# extract rows which contain the variable
fish.test <- fish.test0[ grep( varlist[ i ], fish.test0$group ), ]
# add a column with your name of choice
fish.test <- cbind( fish.test, c( 1: length( fish.test$group ) ) )
colnames( fish.test )[ length( fish.test ) ] <- column
# write each result into your defined list
tests[[ i ]] <- fish.test
}
I have a shinyscript prepared where i want to show a graph based on two widgets.
The first widget(selectInput) controls for the area i want to show a diagnostic plot for.
The second widget (checkboxGroupInput) controls for the amount of data i want to show for the area selected with the first widget. So, the options for the checkboxes depend on what is selected with the selectInput.
I solved this with a htmlOutput("") in the UI and a corresponding renderUI in the server.
Everything works fine, but when i proceed to the plotting, something weird happens.
I can use a reactive filter to control for the area as selected with selectInput, but when i extend the filter to also work work with the checkboxGroupInputi get the following error when i run the app:
Warning: Error in : Problem with filter() input ..2.
x Input ..2 must be of size 611 or 1, not size 0.
i Input ..2 is Code == input$code.
202:
This only shows when all the checkboxes are unchecked and no graph is visible. I Can plot the graph that corresponds with the checkboxes, but it only shows 5 barcharts (when for example ten are to be plotted) and the error is given.
Can someone tell me if there is something wrong with m code? And how i can resolve the error and work with these dependand widgets?
Below my code and data
Code
#libraries needed
library(shiny)
library(ggplot2)
library(dplyr)
#data needed
df <- "load in data"
# user interface ----
ui <- fluidPage(
tabsetPanel(
tabPanel("diagnostische tabellen",fluid = TRUE,
titlePanel("PQ analyse"),
sidebarLayout(
sidebarPanel(
helpText("selecteer terrein waar je de PQ-data van wil bekijken"),
#make first dropdownmenu for area
selectInput("terrein",
label = "Kies een terrein",
choices = sort((unique(df$Terrein))),
selected = 1),
htmlOutput("code")
),
mainPanel(plotOutput("map1"))))
)
)
# Server logic ----------------------------
server <- function(input, output){
# ceate a reactive list of PQ-codes based on previous selection for area
output$code <- renderUI({
data_available <- df[df$Terrein == input$terrein, "Code"]
checkboxGroupInput("code",
label = "PQ-code",
choices = sort(unique(data_available)),
selected = unique(data_available))
})
## filter the data for the graph
filtered_data <- reactive({
filter(df, Terrein == input$terrein, Code == input$code)
})
## GGplot graph
output$map1 <- renderPlot({
ggplot(filtered_data(), aes( x = Code, fill = as.character(Jaar))) +
geom_bar(position = position_stack(reverse = TRUE))+
theme(axis.text.x = element_text(angle = 45, size = 15))+
scale_fill_brewer()+
labs(fill='Jaar')+
ggtitle(paste("Aantal herhalingen PQ's op",input$terrein))
})
}
# Run app
shinyApp(ui, server)
df
structure(list(Terrein = structure(c(25L, 25L, 25L, 25L, 1L,
1L, 1L, 1L, 1L, 1L, 29L, 29L, 13L, 13L, 13L, 7L, 7L, 7L, 7L,
7L, 7L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 8L, 8L, 8L, 13L, 8L, 8L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L,
13L, 13L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 15L, 15L, 15L, 15L,
16L, 16L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 13L, 13L,
13L, 13L, 24L, 24L, 24L, 24L, 28L, 28L, 28L, 28L, 2L, 2L, 2L,
2L, 2L, 2L, 23L, 23L, 23L, 23L, 23L, 22L, 21L, 21L, 21L, 21L,
21L, 7L, 7L, 7L, 7L, 7L, 7L, 20L, 20L, 20L, 20L, 20L, 20L, 20L,
14L, 14L, 14L, 14L, 14L, 14L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
18L, 18L, 18L, 18L, 30L, 30L, 30L, 30L, 20L, 10L, 10L, 10L, 10L,
10L, 13L, 13L, 13L, 6L, 6L, 6L, 6L, 6L, 5L, 5L, 5L, 3L, 3L, 3L,
3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 25L, 1L, 1L, 17L, 17L, 17L, 17L,
13L, 13L, 13L, 13L, 13L, 13L, 23L, 23L, 23L, 23L, 23L, 3L, 3L,
3L, 13L, 3L, 10L, 10L, 25L, 25L, 25L, 25L, 14L, 14L, 14L, 14L,
14L, 14L, 23L, 23L, 23L, 23L, 23L, 15L, 15L, 15L, 15L, 16L, 16L,
16L, 5L, 5L, 5L, 5L, 5L, 12L, 12L, 12L, 12L, 12L, 19L, 15L, 15L,
15L, 15L, 9L, 16L, 16L, 16L, 8L, 19L, 16L, 19L, 8L, 8L, 16L,
16L, 16L, 8L, 8L, 8L, 8L, 8L, 19L, 16L, 19L, 8L, 16L, 16L, 16L,
8L, 16L, 25L, 15L, 15L, 15L, 15L, 15L, 15L, 25L, 21L, 21L, 21L,
7L, 7L, 7L, 12L, 12L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 10L, 10L, 10L, 15L, 15L, 28L, 28L,
28L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 25L, 25L, 25L, 7L, 7L,
7L, 22L, 23L, 23L, 23L, 23L, 23L, 1L, 1L, 1L, 1L, 1L, 23L, 23L,
23L, 23L, 15L, 15L, 15L, 15L, 29L, 29L, 26L, 26L, 26L, 26L, 26L,
26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L,
26L, 7L, 7L, 7L, 5L, 5L, 5L, 5L, 5L, 20L, 12L, 12L, 8L, 20L,
20L, 20L, 20L, 7L, 7L, 7L, 12L, 25L, 25L, 25L, 24L, 24L, 24L,
20L, 20L, 15L, 15L, 15L, 15L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 15L, 15L,
15L, 15L, 14L, 14L, 14L, 14L, 14L, 14L, 12L, 8L, 8L, 8L, 8L,
21L, 21L, 21L, 12L, 10L, 2L, 1L, 1L, 1L, 1L, 1L, 10L, 10L, 15L,
15L, 15L, 15L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L,
26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 6L, 6L, 6L, 6L,
6L, 14L, 14L, 14L, 14L, 23L, 23L, 23L, 23L, 15L, 15L, 15L, 15L,
15L, 15L, 15L, 15L, 21L, 21L, 21L, 26L, 26L, 26L, 25L, 25L, 23L,
23L, 23L, 23L, 26L, 26L, 26L, 13L, 15L, 15L, 15L, 15L, 10L, 10L,
10L, 10L, 26L, 26L, 26L, 13L, 13L, 13L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 23L, 23L, 23L, 23L, 23L, 1L, 1L, 1L, 1L,
1L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 15L, 15L, 15L, 15L, 23L,
23L, 23L, 23L, 23L, 12L, 12L, 12L, 12L, 13L, 13L, 13L, 13L, 13L,
25L, 25L, 21L, 21L, 21L, 12L, 13L, 13L, 13L, 13L, 2L), .Label = c("Arnhemse Heide",
"ASK Doornspijkse Heide", "ASK Oldenbroekse Heide", "Balloërveld",
"Convooi AOCS Nieuw-Milligen", "De Dellen", "de Kom", "De Stompert & Vlasakkers",
"Deelen, VB", "Eder- en Ginkelse Heide", "Ermelosche Heide",
"Havelte", "ISK Harskamp", "Joost Dourleinkazerne", "Kruispeel en Achterbroek",
"Leusderheide", "Luitenant-Generaal Best Kazerne (vml. VB de Peel)",
"Olst-Welsum", "Oude Kamp", "Oude Molen", "Radiostation Noordwijk",
"Rucphense Heide", "Schinveldse Bossen", "Stroese Zand", "Uilenbosch (Waalsdorp)",
"Vliehors", "Vughtse Heide", "Weerter- en Bosoverheide", "Woensdrechtse Heide",
"Zwaluwenberg"), class = "factor"), Code = structure(c(230L,
228L, 228L, 231L, 4L, 5L, 6L, 1L, 2L, 3L, 239L, 240L, 100L, 101L,
102L, 116L, 117L, 118L, 119L, 120L, 121L, 10L, 7L, 8L, 9L, 10L,
11L, 12L, 13L, 26L, 27L, 28L, 30L, 29L, 14L, 15L, 16L, 23L, 24L,
25L, 17L, 18L, 19L, 20L, 21L, 22L, 44L, 45L, 46L, 47L, 48L, 49L,
216L, 217L, 218L, 102L, 214L, 215L, 31L, 42L, 35L, 36L, 37L,
38L, 43L, 32L, 33L, 34L, 39L, 40L, 41L, 71L, 71L, 72L, 59L, 60L,
61L, 62L, 57L, 65L, 63L, 64L, 58L, 55L, 56L, 67L, 68L, 68L, 69L,
70L, 70L, 91L, 92L, 78L, 79L, 80L, 73L, 74L, 75L, 76L, 77L, 103L,
100L, 105L, 108L, 102L, 101L, 104L, 109L, 107L, 106L, 94L, 95L,
93L, 96L, 99L, 97L, 98L, 122L, 123L, 124L, 125L, 135L, 136L,
225L, 222L, 219L, 220L, 221L, 223L, 226L, 224L, 227L, 106L, 105L,
107L, 104L, 188L, 189L, 186L, 187L, 236L, 235L, 237L, 238L, 55L,
56L, 57L, 58L, 59L, 60L, 176L, 177L, 178L, 179L, 180L, 175L,
143L, 144L, 145L, 146L, 147L, 116L, 119L, 117L, 118L, 121L, 120L,
163L, 165L, 160L, 161L, 162L, 164L, 166L, 111L, 110L, 112L, 113L,
114L, 115L, 84L, 85L, 86L, 87L, 88L, 89L, 90L, 167L, 168L, 169L,
170L, 241L, 242L, 242L, 242L, 160L, 73L, 74L, 77L, 80L, 75L,
103L, 105L, 107L, 50L, 51L, 52L, 53L, 54L, 138L, 139L, 140L,
151L, 152L, 153L, 158L, 159L, 1L, 2L, 3L, 4L, 5L, 6L, 231L, 1L,
2L, 171L, 172L, 173L, 174L, 100L, 102L, 108L, 101L, 109L, 104L,
176L, 177L, 178L, 179L, 180L, 154L, 155L, 156L, 106L, 157L, 79L,
78L, 230L, 229L, 228L, 230L, 115L, 114L, 113L, 112L, 110L, 111L,
176L, 177L, 178L, 179L, 180L, 122L, 123L, 124L, 125L, 137L, 135L,
136L, 141L, 142L, 138L, 139L, 140L, 97L, 95L, 96L, 99L, 98L,
150L, 126L, 127L, 128L, 129L, 190L, 133L, 134L, 132L, 213L, 148L,
131L, 149L, 211L, 212L, 133L, 134L, 132L, 210L, 213L, 210L, 212L,
211L, 148L, 131L, 149L, 210L, 134L, 133L, 132L, 213L, 130L, 231L,
125L, 128L, 129L, 127L, 126L, 124L, 231L, 145L, 144L, 143L, 118L,
120L, 117L, 93L, 94L, 160L, 161L, 166L, 165L, 164L, 163L, 162L,
89L, 88L, 85L, 84L, 90L, 86L, 87L, 79L, 78L, 91L, 123L, 122L,
238L, 237L, 235L, 92L, 80L, 75L, 74L, 76L, 77L, 73L, 232L, 233L,
234L, 119L, 121L, 116L, 175L, 176L, 177L, 179L, 180L, 178L, 2L,
3L, 5L, 4L, 1L, 176L, 178L, 179L, 180L, 126L, 127L, 128L, 129L,
239L, 240L, 191L, 192L, 193L, 194L, 195L, 196L, 197L, 198L, 199L,
200L, 201L, 202L, 203L, 204L, 205L, 206L, 207L, 208L, 209L, 116L,
121L, 119L, 138L, 142L, 141L, 139L, 140L, 161L, 94L, 95L, 183L,
166L, 165L, 160L, 163L, 117L, 120L, 118L, 93L, 233L, 234L, 232L,
189L, 187L, 186L, 162L, 164L, 128L, 126L, 129L, 127L, 74L, 75L,
80L, 76L, 77L, 73L, 79L, 78L, 91L, 92L, 100L, 103L, 108L, 101L,
109L, 106L, 105L, 104L, 123L, 124L, 125L, 122L, 115L, 114L, 113L,
112L, 111L, 110L, 97L, 182L, 184L, 185L, 181L, 145L, 144L, 143L,
96L, 82L, 66L, 2L, 3L, 4L, 5L, 1L, 83L, 81L, 128L, 129L, 126L,
127L, 209L, 206L, 207L, 208L, 191L, 192L, 193L, 194L, 203L, 204L,
205L, 198L, 197L, 196L, 195L, 202L, 201L, 199L, 200L, 52L, 51L,
53L, 50L, 54L, 112L, 115L, 114L, 110L, 180L, 179L, 176L, 178L,
122L, 124L, 126L, 127L, 128L, 129L, 123L, 125L, 145L, 144L, 143L,
192L, 195L, 195L, 233L, 234L, 178L, 176L, 180L, 179L, 191L, 194L,
197L, 103L, 128L, 129L, 126L, 127L, 80L, 76L, 79L, 78L, 193L,
198L, 200L, 101L, 100L, 108L, 81L, 83L, 82L, 73L, 74L, 75L, 77L,
91L, 92L, 176L, 177L, 178L, 180L, 179L, 1L, 2L, 3L, 4L, 5L, 93L,
94L, 95L, 96L, 99L, 98L, 97L, 128L, 129L, 126L, 127L, 176L, 178L,
177L, 179L, 180L, 94L, 97L, 95L, 96L, 105L, 107L, 106L, 109L,
104L, 233L, 234L, 143L, 144L, 145L, 93L, 108L, 101L, 100L, 103L,
58L), .Label = c("AhQ001", "AhQ002", "AhQ003", "AhQ004", "AhQ005",
"AhQ006", "BvB001", "BvB002", "BvB003", "BvB028", "BvB029", "BvB033",
"BvB034", "BvExA1", "BvExA2", "BvExA3", "BvExB1", "BvExB2", "BvExB3",
"BvExC1", "BvExC2", "BvExC3", "BvExD1", "BvExD2", "BvExD3", "BvQ004",
"BvQ005", "BvQ006", "BvQ008", "BvQ009", "BvQ028", "BvQ029", "BvQ030",
"BvQ031", "BvQ056", "BvQ057", "BvQ061", "BvQ062", "BvQ074", "BvQ075",
"BvQ076", "BvQ077", "BvQ078", "BvQ104", "BvQ105", "BvQ120", "BvQ121",
"BvQ182", "BvQ183", "DeQ001", "DeQ002", "DeQ003", "DeQ004", "DeQ005",
"DsQ001", "DsQ002", "DsQ003", "DsQ004", "DsQ005", "DsQ006", "DsQ007",
"DsQ008", "DsQ009", "DsQ010", "DsQ011", "DsQ023", "DsQB01", "DsQB02",
"DsQB03", "DsQB04", "DsQB05", "DsQB06", "EhQ001", "EhQ002", "EhQ003",
"EhQ004", "EhQ005", "EhQ006", "EhQ007", "EhQ008", "EhQJ01", "EhQJ02",
"EhQJ03", "ErQ001", "ErQ002", "ErQ003", "ErQ004", "ErQ005", "ErQ006",
"ErQ007", "GiQ001", "GiQ002", "HaQ001", "HaQ002", "HaQ003", "HaQ004",
"HaQ005", "HaQ006", "HaQ007", "HkQ001", "HkQ002", "HkQ003", "HkQ004",
"HkQ005", "HkQ006", "HkQ007", "HkQ008", "HkQ009", "HkQ010", "JdQ001",
"JdQ002", "JdQ003", "JdQ004", "JdQ005", "JdQ006", "KoQ001", "KoQ002",
"KoQ003", "KoQ004", "KoQ005", "KoQ006", "KrQ001", "KrQ002", "KrQ003",
"KrQ004", "KrQ005", "KrQ006", "KrQ007", "KrQ008", "LhH004", "LhPro1",
"LhPro2", "LhPro4", "LhPRro3", "LhQ001", "LhQ002", "LhX031",
"NmQ001", "NmQ002", "NmQ003", "NmQ004", "NmQ005", "NrQ001", "NrQ002",
"NrQ003", "NrQ004", "NrQ005", "OkPro1", "OkPro2", "OkQ001", "OlQ001",
"OlQ002", "OlQ003", "OlQ004", "OlQ005", "OlQ006", "OlQ007", "OlR001",
"OlR002", "OmQ001", "OmQ002", "OmQ003", "OmQ004", "OmQ005", "OmQ006",
"OmQ007", "OwQ001", "OwQ002", "OwQ003", "OwQ004", "PeH011", "PeH012",
"PeH013", "PeH014", "RhQ001", "SbQ001", "SbQ002", "SbQ003", "SbQ004",
"SbQ005", "StQ001", "StQ002", "StQ003", "StQ004", "StQ005", "SzQ001",
"SzQ002", "SzQ003", "SzQ004", "VdR070", "VhQ001", "VhQ002", "VhQ003",
"VhQ004", "VhQ005", "VhQ006", "VhQ007", "VhQ008", "VhQ009", "VhQ010",
"VhQ011", "VhQ012", "VhQ013", "VhQ014", "VhQ015", "VhQ016", "VhQ017",
"VhQ018", "VhQ019", "VlPro1", "VlPro2", "VlPro3", "VlPro4", "VlQ001",
"VlQ002", "VlQ003", "VlQ004", "VlQ005", "VuQ001", "VuQ002", "VuQ003",
"VuQ004", "VuQ005", "VuQ006", "VuT001", "VuT002", "VuT003", "WaQ001",
"WaQ002", "WaQ003", "WaQ004", "WaQ005", "WaQ006", "WaQ007", "WeQ001",
"WeQ002", "WeQ003", "WeQ004", "WhQ001", "WhQ002", "ZwQ001", "ZwQ002"
), class = "factor")), row.names = c(NA, -611L), class = "data.frame")
As you have multiple Codes for each Terrein, you should use %in%. Also, you need to define each bar count. Try this
# user interface ----
ui <- fluidPage(
tabsetPanel(
tabPanel("diagnostische tabellen",fluid = TRUE,
titlePanel("PQ analyse"),
sidebarLayout(
sidebarPanel(
helpText("selecteer terrein waar je de PQ-data van wil bekijken"),
#make first dropdownmenu for area
selectInput("terrein",
label = "Kies een terrein",
choices = sort((unique(df$Terrein))),
selected = 1),
uiOutput("mycode")
),
mainPanel(plotOutput("map1"))))
)
)
# Server logic ----------------------------
server <- function(input, output){
# ceate a reactive list of PQ-codes based on previous selection for area
output$mycode <- renderUI({
data_available <- df[df$Terrein == input$terrein, "Code"]
checkboxGroupInput("code",
label = "PQ-code",
choices = sort(unique(data_available)),
selected = unique(data_available))
})
## filter the data for the graph
filtered_data <- reactive({
dat <- filter(df, Terrein == input$terrein & Code %in% input$code)
data <- dat %>% group_by(Code) %>%
dplyr::summarise(n=n())
data
})
## GGplot graph
output$map1 <- renderPlot({
ggplot(filtered_data(), aes( x = Code, y=n, fill = Code )) +
geom_bar(position = position_stack(reverse = TRUE), stat = "identity")+
theme(axis.text.x = element_text(angle = 45, size = 15))+
scale_fill_brewer()+
labs(fill=NULL)+
ggtitle(paste("Aantal herhalingen PQ's op",input$terrein))
})
}
# Run app
shinyApp(ui, server)
You will get this output:
Please note that there is no Jaar defined, so you may need to define it.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I conduct TS analysis.
My dput().
df=structure(list(month = structure(c(5L, 4L, 8L, 1L, 9L, 7L, 6L,
2L, 12L, 11L, 10L, 3L, 5L, 4L, 8L, 1L, 9L, 7L, 6L, 2L, 12L, 11L,
10L, 3L, 5L, 4L, 8L, 1L, 9L, 7L, 6L, 2L, 12L, 11L, 10L, 3L, 5L,
4L, 8L, 1L, 9L, 7L, 6L, 2L, 12L, 11L, 10L, 3L, 5L, 4L, 8L, 1L,
9L, 7L, 6L, 2L, 12L, 11L, 10L, 3L, 5L, 4L, 8L, 1L, 9L, 7L, 6L,
2L, 12L, 11L, 10L, 3L, 5L, 4L, 8L, 1L, 9L, 7L, 6L, 2L, 12L, 11L,
10L, 3L, 5L, 4L, 8L, 1L, 9L, 7L, 6L, 2L, 12L, 11L, 10L, 3L, 5L,
4L, 8L, 1L), .Label = c("Apr", "Aug", "Dec", "Feb", "Jan", "Jul",
"Jun", "Mar", "May", "Nov", "Oct", "Sep"), class = "factor"),
year = c(1979L, 1979L, 1979L, 1979L, 1979L, 1979L, 1979L,
1979L, 1979L, 1979L, 1979L, 1979L, 1980L, 1980L, 1980L, 1980L,
1980L, 1980L, 1980L, 1980L, 1980L, 1980L, 1980L, 1980L, 1981L,
1981L, 1981L, 1981L, 1981L, 1981L, 1981L, 1981L, 1981L, 1981L,
1981L, 1981L, 1982L, 1982L, 1982L, 1982L, 1982L, 1982L, 1982L,
1982L, 1982L, 1982L, 1982L, 1982L, 1983L, 1983L, 1983L, 1983L,
1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1984L,
1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L,
1984L, 1984L, 1985L, 1985L, 1985L, 1985L, 1985L, 1985L, 1985L,
1985L, 1985L, 1985L, 1985L, 1985L, 1986L, 1986L, 1986L, 1986L,
1986L, 1986L, 1986L, 1986L, 1986L, 1986L, 1986L, 1986L, 1987L,
1987L, 1987L, 1987L), cake = structure(c(54L, 33L, 62L, 70L,
92L, 97L, 3L, 99L, 80L, 88L, 73L, 83L, 46L, 26L, 53L, 61L,
87L, 94L, 2L, 96L, 74L, 82L, 65L, 77L, 38L, 20L, 45L, 52L,
81L, 90L, 1L, 93L, 66L, 76L, 56L, 69L, 30L, 15L, 37L, 44L,
75L, 85L, 100L, 89L, 57L, 68L, 47L, 60L, 23L, 11L, 29L, 36L,
67L, 79L, 98L, 84L, 48L, 59L, 39L, 51L, 18L, 8L, 22L, 28L,
58L, 72L, 95L, 78L, 40L, 50L, 31L, 43L, 14L, 6L, 17L, 21L,
49L, 64L, 91L, 71L, 32L, 42L, 24L, 35L, 10L, 5L, 13L, 16L,
41L, 55L, 86L, 63L, 25L, 34L, 19L, 27L, 7L, 4L, 9L, 12L), .Label = c("10154.696",
"10379.224", "10603.752", "5689.504", "5914.032", "6138.560",
"6238.622", "6363.087", "6442.272", "6463.150", "6587.615",
"6650.772", "6666.799", "6687.677", "6812.142", "6875.300",
"6891.327", "6912.205", "6998.555", "7036.670", "7099.828",
"7115.855", "7136.733", "7223.083", "7248.663", "7261.198",
"7297.533", "7324.355", "7340.382", "7361.260", "7447.610",
"7473.191", "7485.725", "7509.326", "7522.060", "7548.883",
"7564.910", "7585.788", "7672.138", "7697.719", "7705.501",
"7733.854", "7746.588", "7773.411", "7789.438", "7810.315",
"7896.666", "7922.246", "7930.029", "7958.381", "7971.115",
"7997.938", "8013.965", "8034.843", "8106.171", "8121.193",
"8146.774", "8154.557", "8182.909", "8195.643", "8222.466",
"8238.493", "8304.060", "8330.699", "8345.721", "8371.301",
"8379.084", "8407.436", "8420.171", "8446.994", "8528.588",
"8555.227", "8570.249", "8595.829", "8603.612", "8631.964",
"8644.698", "8753.116", "8779.754", "8820.357", "8828.140",
"8856.492", "8869.226", "8977.643", "9004.282", "9032.058",
"9052.667", "9081.019", "9202.171", "9228.809", "9256.586",
"9277.195", "9426.698", "9453.337", "9481.114", "9651.226",
"9677.865", "9705.641", "9875.754", "9930.169"), class = "factor"),
icecream = structure(c(79L, 63L, 81L, 84L, 95L, 97L, 100L,
98L, 88L, 91L, 82L, 87L, 62L, 48L, 67L, 72L, 89L, 93L, 99L,
94L, 76L, 83L, 70L, 74L, 50L, 33L, 52L, 58L, 78L, 85L, 96L,
90L, 65L, 73L, 57L, 64L, 38L, 24L, 41L, 46L, 68L, 75L, 92L,
80L, 54L, 61L, 47L, 53L, 28L, 14L, 30L, 36L, 56L, 66L, 86L,
71L, 42L, 49L, 37L, 43L, 19L, 9L, 21L, 25L, 45L, 55L, 77L,
60L, 31L, 39L, 27L, 32L, 12L, 5L, 13L, 17L, 35L, 44L, 69L,
51L, 22L, 29L, 18L, 23L, 7L, 2L, 8L, 10L, 26L, 34L, 59L,
40L, 15L, 20L, 11L, 16L, 3L, 1L, 4L, 6L), .Label = c("3385.834",
"3778.830", "3948.779", "4124.808", "4178.019", "4319.547",
"4342.230", "4517.359", "4585.426", "4711.662", "4736.627",
"4742.014", "4915.965", "5004.123", "5014.631", "5021.709",
"5109.700", "5131.026", "5150.224", "5261.328", "5322.590",
"5410.013", "5415.633", "5439.154", "5515.562", "5527.707",
"5532.057", "5570.050", "5656.213", "5740.192", "5812.339",
"5816.038", "5899.870", "5914.260", "5925.189", "5932.101",
"5941.954", "6006.774", "6057.884", "6084.031", "6173.592",
"6224.003", "6225.088", "6311.199", "6330.308", "6363.928",
"6364.167", "6407.747", "6468.652", "6470.314", "6479.920",
"6631.617", "6646.099", "6648.738", "6715.593", "6745.815",
"6804.502", "6819.387", "6826.069", "6882.919", "6892.105",
"6984.050", "7046.898", "7084.607", "7092.952", "7130.098",
"7134.058", "7176.124", "7222.477", "7274.188", "7295.503",
"7316.767", "7334.341", "7551.164", "7558.942", "7569.422",
"7626.165", "7629.133", "7648.558", "7721.562", "7752.579",
"7801.250", "7807.326", "7917.988", "8009.607", "8039.695",
"8071.334", "8112.267", "8121.785", "8167.836", "8341.913",
"8467.124", "8497.833", "8647.995", "8708.185", "8915.546",
"9071.327", "9199.960", "9399.616", "9961.726"), class = "factor"),
kex = structure(c(37L, 28L, 46L, 55L, 91L, 4L, 21L, 13L,
73L, 90L, 66L, 82L, 41L, 32L, 50L, 59L, 100L, 8L, 24L, 16L,
78L, 95L, 69L, 85L, 43L, 35L, 53L, 62L, 2L, 10L, 27L, 19L,
81L, 97L, 71L, 87L, 45L, 36L, 54L, 63L, 3L, 11L, 26L, 18L,
80L, 96L, 70L, 86L, 44L, 34L, 52L, 61L, 1L, 9L, 25L, 17L,
77L, 94L, 68L, 84L, 42L, 33L, 51L, 60L, 99L, 7L, 23L, 15L,
76L, 92L, 67L, 83L, 40L, 31L, 49L, 58L, 98L, 6L, 22L, 14L,
74L, 89L, 65L, 79L, 39L, 30L, 48L, 57L, 93L, 5L, 20L, 12L,
72L, 88L, 64L, 75L, 38L, 29L, 47L, 56L), .Label = c("10012.354",
"10027.147", "10031.100", "10284.403", "10298.083", "10350.199",
"10394.860", "10408.841", "10429.411", "10448.012", "10449.622",
"10524.089", "10551.548", "10577.256", "10623.312", "10654.457",
"10659.784", "10682.780", "10685.561", "11238.047", "11245.777",
"11290.695", "11336.062", "11358.832", "11371.587", "11393.214",
"11393.847", "7924.553", "7993.174", "8049.233", "8099.100",
"8114.649", "8140.749", "8171.107", "8173.470", "8185.131",
"8421.128", "8528.465", "8584.070", "8633.341", "8636.581",
"8674.186", "8701.261", "8703.415", "8715.747", "8724.407",
"8759.735", "8816.240", "8866.689", "8893.873", "8909.120",
"8940.573", "8947.258", "8956.228", "8975.999", "8981.998",
"9038.938", "9089.956", "9128.165", "9133.149", "9165.665",
"9176.489", "9182.893", "9260.483", "9315.139", "9339.247",
"9363.164", "9402.322", "9417.254", "9429.165", "9437.884",
"9482.695", "9528.447", "9536.369", "9573.356", "9583.098",
"9620.489", "9622.236", "9628.487", "9644.810", "9649.651",
"9667.118", "9677.137", "9717.143", "9738.233", "9745.187",
"9755.734", "9757.324", "9811.494", "9820.126", "9846.204",
"9858.879", "9883.296", "9897.166", "9905.657", "9922.767",
"9929.587", "9934.869", "9978.806", "9983.549"), class = "factor"),
bread = structure(c(84L, 74L, 85L, 88L, 96L, 97L, 100L, 98L,
91L, 92L, 83L, 89L, 68L, 57L, 71L, 75L, 87L, 93L, 99L, 94L,
79L, 81L, 72L, 77L, 54L, 41L, 58L, 62L, 78L, 82L, 95L, 86L,
66L, 70L, 60L, 64L, 40L, 28L, 46L, 49L, 67L, 73L, 90L, 76L,
53L, 59L, 47L, 52L, 29L, 19L, 34L, 38L, 55L, 63L, 80L, 65L,
43L, 48L, 36L, 42L, 20L, 11L, 23L, 27L, 44L, 51L, 69L, 56L,
32L, 37L, 25L, 31L, 12L, 6L, 15L, 17L, 33L, 39L, 61L, 45L,
22L, 26L, 16L, 21L, 7L, 2L, 8L, 10L, 24L, 30L, 50L, 35L,
14L, 18L, 9L, 13L, 3L, 1L, 4L, 5L), .Label = c("2166.345",
"2648.523", "2736.609", "2898.017", "3085.471", "3140.171",
"3219.482", "3379.514", "3539.234", "3566.302", "3644.388",
"3712.041", "3816.960", "3832.007", "3870.272", "4023.558",
"4056.190", "4071.310", "4165.873", "4217.487", "4300.558",
"4317.832", "4373.292", "4374.852", "4518.024", "4556.376",
"4558.044", "4712.338", "4740.699", "4753.932", "4794.067",
"4814.280", "4863.891", "4893.102", "4908.819", "5026.050",
"5051.821", "5076.228", "5242.140", "5289.752", "5298.084",
"5300.797", "5325.007", "5364.609", "5395.421", "5437.073",
"5552.911", "5561.179", "5617.793", "5658.289", "5741.750",
"5825.819", "5855.726", "5879.818", "5881.214", "5892.896",
"5955.957", "6018.704", "6089.938", "6107.488", "6145.685",
"6195.500", "6256.822", "6377.603", "6405.031", "6416.234",
"6420.458", "6546.651", "6644.214", "6647.421", "6668.263",
"6706.952", "6793.825", "6814.597", "6837.318", "6937.775",
"6972.282", "6994.417", "7026.075", "7157.797", "7251.932",
"7364.200", "7394.167", "7444.071", "7495.351", "7501.435",
"7629.006", "7637.950", "7648.955", "7692.634", "7737.427",
"7950.654", "7992.020", "8116.917", "8259.580", "8406.970",
"8750.245", "8842.216", "8881.043", "9621.858"), class = "factor"),
pie = structure(c(69L, 67L, 72L, 79L, 6L, 25L, 56L, 39L,
95L, 9L, 91L, 2L, 74L, 68L, 81L, 86L, 21L, 41L, 60L, 47L,
7L, 19L, 99L, 12L, 80L, 70L, 84L, 93L, 29L, 46L, 61L, 50L,
14L, 26L, 4L, 20L, 82L, 71L, 88L, 97L, 35L, 48L, 62L, 54L,
17L, 32L, 11L, 23L, 83L, 73L, 92L, 1L, 38L, 49L, 63L, 55L,
22L, 36L, 13L, 28L, 85L, 75L, 94L, 3L, 42L, 51L, 64L, 57L,
24L, 37L, 15L, 31L, 87L, 76L, 96L, 5L, 44L, 52L, 65L, 58L,
27L, 40L, 16L, 33L, 89L, 77L, 98L, 8L, 45L, 53L, 66L, 59L,
30L, 43L, 18L, 34L, 90L, 78L, 100L, 10L), .Label = c("10021.538",
"10089.497", "10090.666", "10134.899", "10143.466", "10147.420",
"10165.583", "10184.298", "10211.385", "10216.074", "10240.421",
"10317.115", "10318.226", "10326.369", "10377.197", "10422.607",
"10437.822", "10457.876", "10461.052", "10462.739", "10476.329",
"10519.485", "10565.467", "10581.157", "10605.485", "10616.507",
"10628.549", "10641.434", "10661.863", "10665.320", "10699.108",
"10724.935", "10743.562", "10778.105", "10786.766", "10804.639",
"10864.942", "10876.955", "10909.292", "10911.331", "10914.655",
"10944.505", "10947.342", "10996.167", "11036.150", "11093.419",
"11185.536", "11214.739", "11302.686", "11351.962", "11368.703",
"11419.258", "11458.410", "11466.567", "11550.255", "11585.645",
"11613.335", "11661.755", "11699.302", "11877.405", "12049.813",
"12167.703", "12253.485", "12318.013", "12367.487", "12405.828",
"8156.854", "8566.438", "8625.615", "8775.256", "8911.947",
"8981.635", "9009.357", "9073.980", "9081.786", "9136.948",
"9179.541", "9212.663", "9256.038", "9291.757", "9359.667",
"9432.769", "9532.766", "9560.171", "9606.922", "9607.613",
"9663.313", "9692.747", "9706.817", "9740.635", "9746.330",
"9787.663", "9800.377", "9858.417", "9903.287", "9912.382",
"9929.028", "9954.085", "9984.490", "9986.527"), class = "factor")), .Names = c("month",
"year", "cake", "icecream", "kex", "bread", "pie"), class = "data.frame", row.names = c(NA,
-100L))
So for 5 positions ( "cake", "icecream", "kex", "bread", "pie"), i want perform forecast!
library(forecast)
ld <- lapply(df, function(x) {ts(c(t(x[,-1])), start = min(x[,1]), frequency = 12)})
lts <- lapply(ld, ets, model = "ZZZ")
lapply(lts, forecast)
After it, the error ocurres.
Error in x[, -1] : incorrect number of dimensions
I think the deal with my data structure, but i can't explane what namely wrong?
How can i understand, why i can't conduct analysis. Maybe i wrong did the grouping?
As final result, i want
month year cake icecream kex bread
Jan 1988 1226 1019 1149 1220
Feb 1988 1627 1530 1649 1341
(it is forecasted value)
This is the continuation of this question: link
The code for the analysis is the same, but the structure of the data is different and that is the problem, if you transform the data to have a structure like the previous one, the problem is solved.
library(reshape)
df <- cast(melt(df, id=c("month", "year"), na.rm=TRUE),
variable + year ~ month)[, c("variable", "year", substring(month.name, 1, 3))]
colnames(df)[1] <- "group"
df[, substring(month.name, 1, 3)] <- lapply(df[, substring(month.name, 1, 3)],
function(x) as.numeric(as.character(x)))
And now this work:
library(forecast)
ld <- split(df[, -1], df$group)
ld <- lapply(ld, function(x) {ts(c(t(x[,-1])), start = min(x[,1]), frequency = 12)})
lts <- lapply(ld, ets, model = "ZZZ")
lf <- lapply(lts, forecast)
lf <- sapply(1:length(lf),
function(x) {d <- as.data.frame(lf[[x]])[, 1, drop = F]
colnames(d) <- names(lf)[x]
d},
simplify = FALSE)
do.call(cbind, lf)
cake icecream kex bread pie
May 1987 7480.974 5134.009 9830.727 3903.814 11068.371
Jun 1987 7881.644 5519.485 10254.112 4285.591 11490.782
Jul 1987 8807.531 6429.317 11193.300 5194.330 12436.630
Aug 1987 8079.533 5685.421 10483.109 4451.265 11729.948
Sep 1987 7024.136 4615.184 9446.217 3383.871 10695.142
...
I'm trying to plot a facets in ggplot2 but I struggle to get the internal ordering of the different facets right. The data looks like this:
head(THAT_EXT)
ID FILE GENRE NODE
1 CKC_1823_01 CKC Novels better
2 CKC_1824_01 CKC Novels better
3 EW9_192_03 EW9 Popular Science better
4 H0B_265_01 H0B Popular Science sad
5 CS2_231_03 CS2 Academic Prose desirable
6 FED_8_05 FED Academic Prose certain
str(THAT_EXT)
'data.frame': 851 obs. of 4 variables:
$ ID : Factor w/ 851 levels "A05_122_01","A05_277_07",..: 345 346 439 608 402 484 319 395 228 5 ...
$ FILE : Factor w/ 241 levels "A05","A06","A0K",..: 110 110 127 169 120 135 105 119 79 2 ...
$ GENRE: Factor w/ 5 levels "Academic Prose",..: 4 4 5 5 1 1 1 5 1 5 ...
$ NODE : Factor w/ 115 levels "absurd","accepted",..: 14 14 14 89 23 16 59 59 18 66 ...
Part of the problem is that can't get the sorting right. Here is the code for the sorting of NODE that I use:
THAT_EXT <- within(THAT_EXT,
NODE <- factor(NODE,
levels=names(sort(table(NODE),
decreasing=TRUE))))
When I plot this with the code below I get a graphs in which the NODE is not correctly sorted in the individual GENREs since different NODEs are more frequent in different GENREs:
p1 <-
ggplot(THAT_EXT, aes(x=NODE)) +
geom_bar() +
scale_x_discrete("THAT_EXT", breaks=NULL) + # supress tick marks on x axis
facet_wrap(~GENRE)
What I want is for every facet to have NODE sorted in decreasing order for that particular GENRE. Can anyone help with this?
structure(list(ID = structure(c(1L, 2L, 3L, 4L, 10L, 133L, 137L,
138L, 139L, 140L, 141L, 142L, 143L, 144L, 145L, 146L, 147L, 148L,
149L, 150L, 151L, 152L, 153L, 154L, 155L, 156L, 157L, 158L, 159L,
160L, 161L, 162L, 163L, 164L, 165L, 166L, 167L, 168L, 169L, 170L,
171L, 172L, 173L, 174L, 175L, 176L, 177L, 178L, 179L, 180L, 181L,
182L, 183L, 184L, 185L, 186L, 187L, 188L, 189L, 190L, 191L, 192L,
193L, 194L, 195L, 196L, 197L, 198L, 199L, 200L, 201L, 202L, 203L,
204L, 205L, 206L, 207L, 208L, 212L, 213L, 214L, 215L, 216L, 217L,
218L, 219L, 220L, 221L, 222L, 223L, 224L, 225L, 226L, 227L, 228L,
229L, 230L, 231L, 232L, 233L, 234L, 235L, 236L, 237L, 238L, 239L,
240L, 241L, 267L, 268L, 269L, 270L, 271L, 272L, 273L, 274L, 275L,
276L, 277L, 278L, 279L, 280L, 281L, 282L, 283L, 284L, 290L, 291L,
298L, 299L, 300L, 303L, 304L, 305L, 306L, 307L, 308L, 309L, 310L,
313L, 314L, 315L, 316L, 317L, 318L, 319L, 327L, 328L, 329L, 330L,
331L, 332L, 333L, 334L, 335L, 336L, 337L, 338L, 339L, 340L, 341L,
342L, 343L, 344L, 345L, 346L, 347L, 348L, 352L, 353L, 354L, 355L,
356L, 357L, 358L, 359L, 360L, 349L, 350L, 351L, 361L, 362L, 363L,
364L, 365L, 366L, 367L, 368L, 369L, 370L, 371L, 372L, 373L, 374L,
375L, 376L, 377L, 378L, 379L, 380L, 381L, 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, 41L, 42L, 43L, 44L, 45L,
46L, 50L, 54L, 72L, 73L, 74L, 75L, 76L, 90L, 91L, 92L, 97L, 98L,
102L, 115L, 125L, 126L, 127L, 128L, 129L, 130L, 131L, 132L, 209L,
210L, 211L, 242L, 243L, 244L, 245L, 246L, 289L, 292L, 293L, 294L,
295L, 296L, 297L, 301L, 302L, 311L, 312L, 320L, 321L, 322L, 323L,
324L, 325L, 326L, 382L, 383L, 384L, 385L, 386L, 387L, 388L, 5L,
6L, 7L, 8L, 9L, 11L, 37L, 38L, 39L, 40L, 47L, 48L, 49L, 51L,
52L, 53L, 55L, 56L, 57L, 58L, 59L, 60L, 61L, 62L, 63L, 64L, 65L,
66L, 67L, 68L, 69L, 70L, 71L, 77L, 78L, 79L, 80L, 81L, 82L, 83L,
84L, 85L, 86L, 87L, 88L, 89L, 93L, 94L, 95L, 96L, 99L, 100L,
101L, 103L, 104L, 105L, 106L, 107L, 108L, 109L, 110L, 111L, 112L,
113L, 114L, 116L, 117L, 118L, 119L, 120L, 121L, 122L, 123L, 124L,
134L, 135L, 136L, 247L, 248L, 249L, 250L, 251L, 252L, 253L, 254L,
255L, 256L, 257L, 258L, 259L, 260L, 261L, 262L, 263L, 264L, 265L,
266L, 285L, 286L, 287L, 288L), .Label = c("A05_122_01", "A05_277_07",
"A05_400_01", "A05_99_01", "A06_1283_02", "A06_1389_01", "A06_1390_01",
"A06_1441_02", "A06_884_03", "A0K_1190_03", "A77_1684_01", "A8K_525_03",
"A8K_582_01", "A8K_645_01", "A8K_799_01", "A90_341_02", "A90_496_01",
"A94_217_01", "A94_472_01", "A94_477_03", "A9M_164_01", "A9M_259_03",
"A9N_199_01", "A9N_489_01", "A9N_591_01", "A9R_173_01", "A9R_425_02",
"A9W_536_02", "AA5_121_01", "AAE_203_01", "AAE_243_01", "AAE_412_01",
"AAW_14_03", "AAW_244_02", "AAW_297_04", "AAW_365_04", "ADG_1398_01",
"ADG_1500_01", "ADG_1507_01", "ADG_1516_01", "AHB_336_01", "AHB_421_01",
"AHJ_1090_02", "AHJ_619_01", "AR3_340_01", "AR3_91_03", "ARF_879_01",
"ARF_985_01", "ARF_991_02", "ARK_1891_01", "ASL_33_04", "ASL_43_01",
"ASL_9_01", "AT7_1031_01", "B09_1162_01", "B09_1475_01", "B09_1493_01",
"B09_1539_01", "B0G_197_01", "B0G_320_01", "B0N_1037_01", "B0N_624_01",
"B0N_645_02", "B0N_683_01", "B3G_313_04", "B3G_320_03", "B3G_398_02",
"B7M_1630_01", "B7M_1913_01", "BNN_746_02", "BNN_895_01", "BP7_2426_01",
"BP7_2777_01", "BP7_2898_01", "BP9_410_01", "BP9_599_01", "BPK_829_01",
"C93_1407_02", "C9A_181_01", "C9A_196_01", "C9A_365_01", "C9A_82_02",
"C9A_9_01", "CB9_306_02", "CB9_63_04", "CB9_86_01", "CBJ_439_01",
"CBJ_702_02", "CBJ_705_01", "CCM_320_01", "CCM_665_01", "CCM_669_02",
"CCN_1036_02", "CCN_1078_01", "CCN_1119_01", "CCN_784_01", "CCW_2284_02",
"CCW_2349_03", "CE7_242_02", "CE7_284_01", "CE7_39_01", "CEB_1675_01",
"CER_145_03", "CER_23_01", "CER_235_02", "CER_378_10", "CET_1056_02",
"CET_680_01", "CET_705_01", "CET_797_01", "CET_838_01", "CET_879_05",
"CET_946_03", "CET_986_01", "CEY_2977_01", "CJ3_107_02", "CJ3_114_03",
"CJ3_20_01", "CJ3_81_01", "CK2_112_01", "CK2_22_01", "CK2_392_01",
"CK2_42_01", "CK2_75_01", "CKC_1776_01", "CKC_1777_01", "CKC_1823_01",
"CKC_1824_01", "CKC_1860_01", "CKC_1883_01", "CKC_1883_02", "CKC_2127_01",
"CMN_1439_02", "CRM_5767_01", "CRM_5770_03", "CRM_5789_01", "CS2_110_01",
"CS2_131_01", "CS2_139_01", "CS2_187_01", "CS2_187_03", "CS2_231_03",
"CS2_249_02", "CS2_301_01", "CS2_35_01", "CS2_58_02", "EV6_16_01",
"EV6_206_02", "EV6_240_01", "EV6_244_02", "EV6_28_01", "EV6_30_01",
"EV6_32_01", "EV6_450_01", "EV6_69_01", "EV6_80_01", "EV6_91_01",
"FAC_1019_01", "FAC_1026_01", "FAC_1027_01", "FAC_1235_01", "FAC_1269_05",
"FAC_1270_05", "FAC_1393_01", "FAC_1406_03", "FAC_933_01", "FAC_950_01",
"FAC_960_01", "FED_105_01", "FED_120_02", "FED_21_02", "FED_281_02",
"FED_302_02", "FED_53_01", "FED_8_05", "FEF_498_03", "FEF_674_03",
"FR2_410_01", "FR2_557_02", "FR2_593_01", "FR2_691_01", "FR4_232_01",
"FR4_331_01", "FR4_346_01", "FS7_818_01", "FS7_919_01", "FU0_368_02",
"FYT_1138_01", "FYT_1183_01", "FYT_901_05", "G08_1336_01", "G1E_385_01",
"G1N_824_01", "G1N_860_01", "G1N_868_01", "G1N_975_01", "GU5_854_01",
"GUJ_423_01", "GUJ_501_01", "GUJ_611_01", "GUJ_629_03", "GUJ_700_01",
"GV0_10_01", "GV0_104_01", "GV0_111_01", "GV0_122_01", "GV0_160_01",
"GV0_232_02", "GV2_1465_01", "GV2_1899_01", "GV6_2683_01", "GW6_297_01",
"GW6_306_05", "GW6_307_01", "GW6_322_01", "GW6_330_02", "GW6_335_01",
"GW6_338_01", "GW6_367_02", "GW6_373_01", "GW6_407_01", "GW6_411_01",
"GW6_413_01", "GW6_421_01", "GW6_423_01", "GW6_424_01", "GW6_428_01",
"GW6_447_01", "GWM_480_01", "GWM_533_02", "GWM_554_02", "GWM_554_03",
"GWM_609_01", "GWM_609_04", "GWM_610_01", "GWM_730_01", "GWM_731_01",
"GWM_738_01", "GWM_804_06", "GWM_815_01", "GWM_832_03", "GVP_179_01",
"GVP_211_01", "GVP_393_02", "GVP_443_02", "GVP_710_01", "H0B_171_04",
"H0B_216_01", "H0B_265_01", "H0B_32_01", "H0B_361_03", "H0B_365_01",
"H0B_369_01", "H0B_74_01", "H0B_93_01", "H10_1002_01", "H10_1032_04",
"H10_653_01", "H10_803_01", "H10_824_01", "H10_825_03", "H10_881_01",
"H10_986_01", "H78_851_04", "H78_891_01", "H78_946_04", "H79_1959_19",
"H7S_110_05", "H7S_130_06", "H7S_131_03", "H7S_131_04", "H7S_146_01",
"H7S_148_01", "H7S_164_01", "H7S_179_01", "H7S_54_01", "H7S_56_05",
"H7S_62_03", "H7S_79_01", "H7S_8_01", "H7S_81_01", "H7S_83_01",
"H7S_87_01", "H7S_92_03", "H7X_1028_02", "H7X_1091_01", "H7X_691_01",
"H7X_695_01", "H8H_2917_01", "H8K_153_01", "H8K_55_01", "H8M_1897_01",
"H8M_2104_02", "H8T_3316_03", "H98_3204_01", "H98_3410_01", "H98_3490_02",
"H9R_130_02", "H9R_39_01", "H9S_1297_01", "HA2_3107_02", "HA2_3284_01",
"HPY_754_04", "HPY_785_09", "HPY_799_03", "HPY_807_04", "HPY_830_04",
"HPY_838_02", "HPY_843_01", "HPY_869_11", "HR7_190_01", "HR7_440_01",
"HTP_540_01", "HTP_585_01", "HTP_588_05", "HTP_593_01", "HTP_601_01",
"HTP_613_01", "HTP_648_02", "HTW_197_01", "HTW_494_01", "HTW_750_01",
"HWL_2770_01", "HWL_2919_01", "HWM_45_01", "HWM_45_02", "HXY_1047_03",
"HXY_701_01", "HXY_781_01", "HXY_783_01", "HXY_784_01", "HXY_836_01",
"HXY_931_01", "HXY_963_01", "HXY_972_01", "HXY_985_03", "HY6_1024_01",
"HY6_1025_01", "HY6_1164_01", "HY6_1223_01", "HY6_988_03", "HY6_989_01",
"HY8_160_01", "HY8_164_01", "HY8_292_03", "HY8_316_01", "HY9_778_03",
"HY9_845_02", "HYX_235_08", "HYX_245_01", "HYX_88_01", "J12_1474_02",
"J12_1492_01", "J12_1571_01", "J12_1845_01", "J14_341_01", "J18_597_04",
"J18_698_02", "J18_759_01", "J18_828_01", "J3R_197_01", "J3R_219_02",
"J3R_277_04", "J3T_267_01", "J3T_269_02", "J3T_57_02", "J41_41_02",
"J41_58_03", "J9B_133_03", "J9B_341_02", "J9B_341_03", "J9D_147_05",
"J9D_218_01", "J9D_411_01", "J9D_616_01", "J9D_616_02", "JNB_563_02",
"JT7_118_01", "JT7_129_02", "JT7_218_02", "JT7_344_02", "JXS_3663_01",
"JXU_407_01", "JXU_468_02", "JXU_559_01", "JXV_1439_04", "JXV_1592_01",
"JY1_100_01"), class = "factor"), GENRE = structure(c(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, 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, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 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, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L), .Label = c("Academic Prose", "Conversation", "News",
"Novels", "Popular Science"), class = "factor"), NODE = structure(c(9L,
10L, 10L, 10L, 4L, 10L, 71L, 35L, 49L, 6L, 5L, 15L, 28L, 44L,
64L, 64L, 28L, 28L, 18L, 18L, 32L, 18L, 58L, 10L, 72L, 28L, 18L,
10L, 64L, 10L, 35L, 64L, 64L, 69L, 8L, 10L, 50L, 69L, 49L, 49L,
15L, 69L, 10L, 49L, 8L, 64L, 49L, 10L, 69L, 18L, 61L, 67L, 67L,
61L, 57L, 69L, 11L, 10L, 64L, 10L, 59L, 61L, 49L, 10L, 59L, 1L,
61L, 35L, 54L, 54L, 39L, 44L, 61L, 64L, 69L, 1L, 23L, 49L, 49L,
8L, 69L, 49L, 69L, 49L, 49L, 69L, 35L, 49L, 49L, 49L, 35L, 10L,
49L, 48L, 10L, 49L, 11L, 44L, 50L, 11L, 50L, 69L, 49L, 10L, 59L,
68L, 47L, 69L, 49L, 35L, 29L, 8L, 49L, 50L, 35L, 10L, 35L, 8L,
35L, 8L, 10L, 35L, 10L, 10L, 10L, 35L, 44L, 61L, 35L, 44L, 28L,
47L, 39L, 39L, 49L, 61L, 43L, 60L, 19L, 10L, 10L, 10L, 44L, 44L,
62L, 44L, 10L, 59L, 10L, 61L, 1L, 53L, 33L, 10L, 8L, 8L, 64L,
64L, 10L, 57L, 61L, 64L, 66L, 19L, 61L, 64L, 10L, 10L, 8L, 19L,
35L, 28L, 10L, 61L, 35L, 42L, 35L, 28L, 32L, 64L, 10L, 18L, 28L,
25L, 35L, 35L, 10L, 18L, 10L, 22L, 55L, 28L, 10L, 1L, 55L, 51L,
1L, 38L, 28L, 28L, 33L, 10L, 44L, 29L, 16L, 8L, 28L, 69L, 32L,
10L, 61L, 20L, 35L, 10L, 28L, 10L, 32L, 10L, 46L, 59L, 64L, 35L,
66L, 2L, 35L, 28L, 30L, 18L, 69L, 32L, 10L, 28L, 17L, 36L, 64L,
61L, 10L, 64L, 33L, 3L, 37L, 26L, 28L, 64L, 44L, 28L, 64L, 64L,
6L, 6L, 64L, 50L, 32L, 8L, 64L, 50L, 28L, 24L, 18L, 47L, 35L,
40L, 24L, 55L, 44L, 22L, 1L, 49L, 44L, 18L, 45L, 63L, 64L, 35L,
12L, 35L, 10L, 35L, 10L, 10L, 10L, 44L, 44L, 44L, 65L, 44L, 55L,
32L, 49L, 64L, 39L, 69L, 1L, 60L, 7L, 14L, 44L, 33L, 10L, 19L,
10L, 70L, 53L, 8L, 61L, 61L, 44L, 61L, 65L, 28L, 68L, 69L, 27L,
61L, 28L, 72L, 34L, 61L, 32L, 10L, 49L, 35L, 49L, 10L, 10L, 69L,
39L, 40L, 19L, 59L, 53L, 49L, 49L, 44L, 49L, 35L, 49L, 61L, 61L,
1L, 10L, 28L, 49L, 35L, 49L, 61L, 50L, 69L, 35L, 61L, 35L, 50L,
10L, 28L, 69L, 61L, 21L, 69L, 29L, 35L, 35L, 35L, 11L, 69L, 8L,
41L, 56L, 35L, 61L, 69L, 49L, 49L, 49L, 1L, 13L, 64L, 64L, 52L,
44L, 64L, 64L, 50L, 49L, 69L, 11L, 59L, 49L, 31L), .Label = c("apparent",
"appropriate", "awful", "axiomatic", "best", "better", "breathtaking",
"certain", "characteristic", "clear", "conceivable", "convenient",
"crucial", "cruel", "desirable", "disappointing", "emphatic",
"essential", "evident", "expected", "extraordinary", "fair",
"fortunate", "Funny", "good", "great", "imperative", "important",
"impossible", "incredible", "inescapable", "inevitable", "interesting",
"ironic", "likely", "Likely", "lucky", "ludicrous", "natural",
"necessary", "needful", "notable", "noteworthy", "obvious", "odd",
"paradoxical", "plain", "plausible", "possible", "probable",
"proper", "relevant", "remarkable", "revealing", "right", "Sad",
"self-evident", "sensible", "significant", "striking", "surprising",
"symptomatic", "terrible", "true", "typical", "understandable",
"unexpected", "unfortunate", "unlikely", "unreasonable", "untrue",
"vital"), class = "factor")), .Names = c("ID", "GENRE", "NODE"
), class = "data.frame", row.names = c(NA, -388L))
As I mentioned already: facet_wrap is not intended for having individual scales. At least I didn't find a solution. Hence, setting the labels in scale_x_discrete did not bring the desired result.
But this my workaround:
library(plyr)
library(ggplot2)
nodeCount <- ddply( df, c("GENRE", "NODE"), nrow )
nodeCount$factors <- paste( nodeCount$GENRE, nodeCount$NODE, sep ="." )
nodeCount <- nodeCount[ order( nodeCount$GENRE, nodeCount$V1, decreasing=TRUE ), ]
nodeCount$factors <- factor( nodeCount$factors, levels=nodeCount$factors )
head(nodeCount)
GENRE NODE V1 factors
121 Popular Science possible 14 Popular Science.possible
128 Popular Science surprising 11 Popular Science.surprising
116 Popular Science likely 9 Popular Science.likely
132 Popular Science unlikely 9 Popular Science.unlikely
103 Popular Science clear 7 Popular Science.clear
129 Popular Science true 5 Popular Science.true
g <- ggplot( nodeCount, aes( y=V1, x = factors ) ) +
geom_bar() +
scale_x_discrete( breaks=NULL ) + # supress tick marks on x axis
facet_wrap( ~GENRE, scale="free_x" ) +
geom_text( aes( label = NODE, y = V1+2 ), angle = 45, vjust = 0, hjust=0, size=3 )
Which gives:
I'm running a report, and have pulled out some data around something happening over time. I have then summarised that data into a dataframe of date/times and counts. When I try to plot it via ggplot2 I get an error
> ggplot(foo, aes(x=Date, y=Count))+
+ geom_line()
Error in cut.default(unclass(x), unclass(breaks), labels = labels, right = right, :
cannot allocate vector of length 1317423601
>
> ggplot(foo[2:349,], aes(x=Date, y=Count))+
+ geom_line()
Plot produced...
My data is using POSIXct dates, which do seem to cover the end of British Summer Time. I also note that if I excldue the first row of data it works !. Any ideas ?
Here's my data
> dput(foo)
structure(list(Date = structure(c(1317423600, 1317445200, 1317466800,
1317488400, 1317510000, 1317553200, 1317574800, 1317596400, 1317618000,
1317639600, 1317661200, 1317682800, 1317704400, 1317726000, 1317747600,
1317769200, 1317790800, 1317812400, 1317834000, 1317855600, 1317877200,
1317898800, 1317920400, 1317942000, 1317963600, 1317985200, 1318006800,
1318028400, 1318050000, 1318071600, 1318093200, 1318114800, 1318136400,
1318158000, 1318179600, 1318201200, 1318222800, 1318244400, 1318266000,
1318287600, 1318309200, 1318330800, 1318352400, 1318374000, 1318395600,
1318417200, 1318438800, 1318460400, 1318503600, 1318525200, 1318546800,
1318568400, 1318590000, 1318611600, 1318633200, 1318654800, 1318676400,
1318698000, 1318719600, 1318762800, 1318784400, 1318806000, 1318827600,
1318849200, 1318870800, 1318892400, 1318914000, 1318935600, 1318957200,
1318978800, 1319000400, 1319022000, 1319043600, 1319065200, 1319086800,
1319108400, 1319130000, 1319151600, 1319173200, 1319194800, 1319216400,
1319238000, 1319259600, 1319281200, 1319302800, 1319324400, 1319346000,
1319367600, 1319410800, 1319432400, 1319454000, 1319475600, 1319497200,
1319518800, 1319540400, 1319562000, 1319583600, 1319605200, 1319626800,
1319648400, 1319670000, 1319691600, 1319713200, 1319734800, 1319756400,
1319778000, 1319799600, 1319821200, 1319842800, 1319864400, 1319886000,
1319907600, 1319929200, 1319994000, 1320015600, 1320037200, 1320058800,
1320080400, 1320102000, 1320123600, 1320145200, 1320166800, 1320188400,
1320210000, 1320231600, 1320253200, 1320274800, 1320296400, 1320318000,
1320339600, 1320361200, 1320382800, 1320404400, 1320426000, 1320447600,
1320469200, 1320490800, 1320512400, 1320534000, 1320577200, 1320598800,
1320620400, 1320642000, 1320663600, 1320685200, 1320706800, 1320750000,
1320771600, 1320793200, 1320814800, 1320836400, 1320858000, 1320879600,
1320901200, 1320922800, 1320944400, 1320966000, 1320987600, 1321009200,
1321030800, 1321052400, 1321074000, 1321095600, 1321117200, 1321138800,
1321182000, 1321203600, 1321225200, 1321246800, 1321268400, 1321290000,
1321311600, 1321333200, 1321354800, 1321376400, 1321398000, 1321419600,
1321441200, 1321462800, 1321484400, 1321506000, 1321527600, 1321549200,
1321570800, 1321592400, 1321614000, 1321635600, 1321657200, 1321678800,
1321700400, 1321722000, 1321743600, 1321765200, 1321786800, 1321808400,
1321830000, 1321851600, 1321873200, 1321894800, 1321916400, 1321938000,
1321959600, 1321981200, 1322002800, 1322024400, 1322046000, 1322067600,
1322089200, 1322110800, 1322132400, 1322154000, 1322175600, 1322197200,
1322218800, 1322240400, 1322262000, 1322305200, 1322326800, 1322370000,
1322391600, 1322413200, 1322434800, 1322456400, 1322478000, 1322499600,
1322521200, 1322542800, 1322564400, 1322586000, 1322607600, 1322629200,
1322650800, 1322672400, 1322694000, 1322715600, 1322737200, 1322758800,
1322780400, 1322802000, 1322823600, 1322845200, 1322866800, 1322888400,
1322910000, 1322931600, 1322953200, 1322974800, 1322996400, 1323018000,
1323039600, 1323061200, 1323082800, 1323104400, 1323126000, 1323147600,
1323169200, 1323190800, 1323212400, 1323234000, 1323255600, 1323277200,
1323298800, 1323320400, 1323342000, 1323363600, 1323385200, 1323406800,
1323428400, 1323450000, 1323471600, 1323493200, 1323514800, 1323558000,
1323579600, 1323601200, 1323622800, 1323644400, 1323666000, 1323687600,
1323709200, 1323730800, 1323752400, 1323774000, 1323795600, 1323817200,
1323838800, 1323860400, 1323882000, 1323903600, 1323925200, 1323946800,
1323968400, 1323990000, 1324011600, 1324033200, 1324054800, 1324076400,
1324098000, 1324119600, 1324141200, 1324162800, 1324206000, 1324227600,
1324249200, 1324270800, 1324292400, 1324314000, 1324335600, 1324357200,
1324378800, 1324400400, 1324422000, 1324443600, 1324465200, 1324486800,
1324508400, 1324530000, 1324551600, 1324573200, 1324594800, 1324616400,
1324638000, 1324659600, 1324681200, 1324702800, 1324724400, 1324767600,
1324832400, 1324854000, 1324875600, 1324897200, 1324918800, 1324940400,
1324962000, 1324983600, 1325005200, 1325026800, 1325048400, 1325070000,
1325091600, 1325113200, 1325134800, 1325156400, 1325178000, 1325199600,
1325221200, 1325242800, 1325264400, 1325286000), class = c("POSIXct",
"POSIXt"), tzone = ""), Count = c(3L, 0L, 9L, 1L, 0L, 1L, 6L,
4L, 4L, 52L, 19L, 7L, 5L, 59L, 30L, 3L, 2L, 50L, 25L, 8L, 4L,
41L, 22L, 4L, 8L, 57L, 12L, 14L, 3L, 10L, 2L, 6L, 0L, 1L, 7L,
10L, 12L, 44L, 19L, 11L, 3L, 47L, 31L, 7L, 9L, 56L, 21L, 11L,
54L, 20L, 10L, 6L, 54L, 17L, 0L, 1L, 11L, 2L, 0L, 2L, 4L, 14L,
9L, 52L, 19L, 11L, 10L, 56L, 33L, 12L, 9L, 57L, 20L, 12L, 5L,
51L, 23L, 14L, 5L, 50L, 9L, 1L, 2L, 5L, 7L, 1L, 0L, 3L, 9L, 13L,
57L, 27L, 10L, 7L, 62L, 29L, 5L, 6L, 53L, 22L, 8L, 10L, 53L,
12L, 7L, 9L, 38L, 8L, 1L, 0L, 9L, 3L, 0L, 6L, 9L, 3L, 81L, 27L,
6L, 5L, 67L, 45L, 6L, 3L, 63L, 43L, 10L, 2L, 57L, 38L, 19L, 12L,
54L, 22L, 1L, 0L, 5L, 4L, 0L, 4L, 2L, 10L, 4L, 53L, 44L, 7L,
65L, 41L, 11L, 7L, 61L, 46L, 7L, 4L, 64L, 48L, 10L, 11L, 56L,
39L, 6L, 1L, 4L, 3L, 0L, 7L, 3L, 10L, 4L, 46L, 45L, 16L, 6L,
69L, 46L, 17L, 1L, 67L, 43L, 15L, 5L, 57L, 40L, 14L, 4L, 56L,
36L, 3L, 0L, 11L, 3L, 0L, 1L, 5L, 2L, 5L, 9L, 59L, 45L, 9L, 7L,
71L, 35L, 19L, 10L, 65L, 23L, 5L, 7L, 10L, 2L, 5L, 6L, 5L, 1L,
0L, 3L, 2L, 0L, 5L, 7L, 10L, 8L, 58L, 46L, 16L, 6L, 70L, 52L,
14L, 8L, 84L, 42L, 10L, 6L, 62L, 44L, 11L, 3L, 58L, 28L, 3L,
0L, 9L, 8L, 1L, 0L, 4L, 2L, 10L, 11L, 65L, 53L, 14L, 11L, 73L,
42L, 14L, 8L, 74L, 33L, 15L, 13L, 75L, 53L, 11L, 10L, 61L, 31L,
1L, 2L, 9L, 2L, 0L, 3L, 1L, 15L, 16L, 114L, 52L, 10L, 14L, 75L,
50L, 14L, 9L, 69L, 52L, 12L, 15L, 77L, 35L, 10L, 5L, 69L, 37L,
5L, 1L, 12L, 10L, 0L, 9L, 4L, 14L, 18L, 90L, 35L, 12L, 9L, 87L,
49L, 10L, 22L, 83L, 41L, 15L, 14L, 79L, 48L, 17L, 6L, 40L, 8L,
2L, 0L, 2L, 0L, 1L, 7L, 2L, 1L, 2L, 6L, 2L, 54L, 31L, 11L, 6L,
54L, 32L, 7L, 9L, 63L, 23L, 16L, 6L, 43L, 17L, 3L)), .Names = c("Date",
"Count"), row.names = c(1L, 2L, 3L, 4L, 5L, 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, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L,
51L, 52L, 53L, 54L, 55L, 56L, 57L, 58L, 59L, 60L, 61L, 63L, 64L,
65L, 66L, 67L, 68L, 69L, 70L, 71L, 72L, 73L, 74L, 75L, 76L, 77L,
78L, 79L, 80L, 81L, 82L, 83L, 84L, 85L, 86L, 87L, 88L, 89L, 90L,
91L, 93L, 94L, 95L, 96L, 97L, 98L, 99L, 100L, 101L, 102L, 103L,
104L, 105L, 106L, 107L, 108L, 109L, 110L, 111L, 112L, 113L, 114L,
115L, 116L, 117L, 120L, 121L, 122L, 123L, 124L, 125L, 126L, 127L,
128L, 129L, 130L, 131L, 132L, 133L, 134L, 135L, 136L, 137L, 138L,
139L, 140L, 141L, 142L, 143L, 144L, 145L, 147L, 148L, 149L, 150L,
151L, 152L, 153L, 155L, 156L, 157L, 158L, 159L, 160L, 161L, 162L,
163L, 164L, 165L, 166L, 167L, 168L, 169L, 170L, 171L, 172L, 173L,
175L, 176L, 177L, 178L, 179L, 180L, 181L, 182L, 183L, 184L, 185L,
186L, 187L, 188L, 189L, 190L, 191L, 192L, 193L, 194L, 195L, 196L,
197L, 198L, 199L, 200L, 201L, 202L, 203L, 204L, 205L, 206L, 207L,
208L, 209L, 210L, 211L, 212L, 213L, 214L, 215L, 216L, 217L, 218L,
219L, 220L, 221L, 222L, 223L, 224L, 225L, 227L, 228L, 230L, 231L,
232L, 233L, 234L, 235L, 236L, 237L, 238L, 239L, 240L, 241L, 242L,
243L, 244L, 245L, 246L, 247L, 248L, 249L, 250L, 251L, 252L, 253L,
254L, 255L, 256L, 257L, 258L, 259L, 260L, 261L, 262L, 263L, 264L,
265L, 266L, 267L, 268L, 269L, 270L, 271L, 272L, 273L, 274L, 275L,
276L, 277L, 278L, 279L, 280L, 281L, 282L, 283L, 285L, 286L, 287L,
288L, 289L, 290L, 291L, 292L, 293L, 294L, 295L, 296L, 297L, 298L,
299L, 300L, 301L, 302L, 303L, 304L, 305L, 306L, 307L, 308L, 309L,
310L, 311L, 312L, 313L, 315L, 316L, 317L, 318L, 319L, 320L, 321L,
322L, 323L, 324L, 325L, 326L, 327L, 328L, 329L, 330L, 331L, 332L,
333L, 334L, 335L, 336L, 337L, 338L, 339L, 341L, 344L, 345L, 346L,
347L, 348L, 349L, 350L, 351L, 352L, 353L, 354L, 355L, 356L, 357L,
358L, 359L, 360L, 361L, 362L, 363L, 364L, 365L), class = "data.frame")
and here's my original code
ggplot(foo, aes(x=Date, y=Count))+
geom_line()