Related
I really cannot find anything usefull online for this problem. I've got dataset where one variable has been measured on 4 different occasion (CRP1, CRP4, CRP7, CRP10) and I've run pairwise Wilcoxon test to compare CRP drop trend between 2 groups. I've also made ggplot to show the significant p values.
Now I want to present my p values through the tbl_summary() function, but it seems that I cannot accomplish that. Wilcoxon test that I've run to get my p values was performed on the long format of my dataset.
structure(list(LEK = 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, 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), levels = c("Lek +", "Lek -"), class = "factor", label = "Terapija"),
CRP1 = c(103.9, 155.6, 102.2, 89.2, 32.3, 258.8, 58.5, 196.7,
89.3, 175, 170.9, 204.3, 82.2, 196.9, 220.4, 92, 37.1, 34,
223.6, 261.5, 82, 37.4, 112, 81.8, 47.5, 70.1, 137.2, 84.7,
151.9, 159.8, 149.7, 140, 37.9, 143, 130.6, 110.7, 112.9,
48.1, 115.5, 43, 102.1, 35.9, 120.3, 40.9, 169.9, 105.6,
90, 139.6, 246.4, 146.9, 13.9, 60.9, 123.1, 187.3, 23.6,
112.9, 17.5, 9.9, 120.4, 103.7, 12.4, 96.7, 144.9, 54.1,
186.6, 143.6, 30.6, 41.8, 146.4, 94.9, 144.2, 98.5, 63.3,
137.1, 81.1, 14.1, 117.3, 55.4, 92.7, 40.3, 189.7, 77.2,
36.7, 73.7, 19.8, 39.1, 119, 60.6, 110.6, 63.2, 135.1, 131.6,
206.9, 117.1, 92.6, 123.3, 297, 153.3, 210.4, 116.1, 59.3,
177.3, 37.1, 101.2, 87.8, 138.6, 88.9, 95.6, 71.6, 81.1,
394.3, 4.8, 36.4, 229.3, 108.4, 404.1, 259.5, 292.9, 134.1,
127.5, 33.2, 29.2, 346.3, 116, 302), CRP4 = c(21, 74.7, 26.3,
48.1, 23.7, 86, 15.1, 33.7, 29.3, 16.9, 115, 79.5, 48, 58.5,
332.2, 153, 28.2, 11.6, 94.4, 50.2, 85.8, 48.7, 25, 14.3,
150.2, 145.5, 64.2, 28, 143.9, 57.6, 11, 132.9, 96.9, 44.4,
200.2, 45.2, 7.4, 95, 38.1, 12.5, 29.2, 6.8, 104.5, 15.3,
32.9, 26.5, 25, 49.7, 142.5, 37.5, 6.4, 32.1, 44.3, 70.9,
22.2, 72.2, 40.2, 3.5, 9.3, 72.5, 36, 17.9, 161.8, 18.5,
48.2, 198.7, 52.8, 77.6, 93.7, 162.7, 45.6, 206.4, 269.9,
21.1, 14.1, 22, 97.3, 52.2, 61, 34.8, 45.9, 43.6, 16.4, 203.6,
35.5, 28.1, 87.7, 23.2, 35.8, 44.2, 104.4, 83.7, 49.2, 23.5,
21.7, 118.6, 78.8, 101.6, 162.5, 23.9, 21.6, 109.3, 62.8,
146.1, 84.6, 57.6, 225.3, 143.4, 104.1, 29.7, 319.5, 104.5,
110.2, 120.3, 99.7, 172.1, 293.3, 262.9, 190.2, 82.4, 129.1,
5.5, 75.2, 36.8, 69.2), CRP7 = c(2.8, 110.8, 63.4, 51.3,
20.8, 27.8, 2.2, 194.6, 24.2, 8.3, 70.7, 93.3, 6.4, 38.3,
188.3, 75.1, 49.4, 5, 107.2, 37.8, 246.3, 26.4, 4.2, 4.3,
28.2, 22.4, 9.1, 195.9, 150.7, 67.4, 8.6, 283.6, 63.1, 100.9,
82.7, 9.9, 7.6, 207, 6.7, 9.2, 245.8, 42.5, 179.8, 12.3,
4.2, 6, 8.8, 5.9, 28.8, 27, 3.5, 24.8, 14.4, 55.5, 3.9, 106.7,
49.8, 11.1, 3.77, 68, 52.4, 32.7, 223.6, 12.3, 117.7, 66.1,
184.5, 29.3, 174.7, 119.3, 80.2, 87.9, 135.6, 22.8, 12.2,
82.7, 9.1, 32.3, 21.3, 82, 12.1, 37.8, 48.2, 56.6, 6.5, 37,
112.9, 11, 142.8, 18.4, 71.5, 91.1, 8.9, 7, 166.7, 55.4,
123.8, 46.8, 64.5, 5, 10.5, 201.7, 188.5, 198.7, 271.8, 276,
181.8, 190.2, 164.6, 65.1, 322.8, 61.9, 195.7, 225.5, 66.6,
119.4, 268.5, 350.3, 223.2, 161, 34.3, 22.4, 243.8, 62, 39.8
), CRP10 = c(NA, NA, NA, 184.3, 4.4, 7.7, NA, NA, 1.2, 1,
1, 12.3, 2.5, 62.2, 43.4, 57.7, 100.3, 15.6, 4.2, 11.5, NA,
8.3, 1, 1.3, 11.9, 63, NA, 71.4, 60.3, 54.6, 6.7, 313.8,
37, NA, 123.7, 2.5, 2.2, NA, 252.4, 9.7, NA, 82.2, 230.8,
5.8, 1, NA, 3.9, 1, 6.9, 34.7, 2.6, NA, 15.2, 6.4, 6.1, NA,
214.7, NA, 22.5, 86.5, 13.9, 41, 246.5, 9, 26.5, 270, 270.8,
7.6, 65.7, 90.5, 202.3, 288.6, 464, 92.1, 19.7, 307.5, 10.6,
71.2, 80.6, 159.8, 4.1, 103.7, 80.6, 324, 9.5, 6.3, 9.6,
4.1, 151.5, 20.3, 63.6, 311, 2.8, 52.8, 62.3, 13.5, 248,
72.2, 83.5, 13.8, 37.8, 179, 72.4, 206.4, 76.4, 210.6, 69.5,
87.9, 303.3, 59.1, 174.5, 211, 211.2, 240.8, 38.6, 109.6,
251.7, 328.9, 87.1, 113.5, 48.9, 16.4, 277, 25.7, 122)), row.names = c(NA,
-125L), class = c("tbl_df", "tbl", "data.frame"))
LongCRP <- Statistika %>%
select(LEK, CRP1, CRP4, CRP7, CRP10) %>%
filter(complete.cases(.)) %>%
gather("Vreme", "CRP", CRP1, CRP4, CRP7, CRP10) %>%
mutate(Vreme = factor(Vreme, levels = c("CRP1", "CRP4", "CRP7", "CRP10"))) #Long format
pairwise.wilcox.CRP <- LongCRP %>%
group_by(LEK) %>%
pairwise_wilcox_test(
CRP ~ Vreme
)
pairwise.wilcox.CRP <- pairwise.wilcox.CRP %>% add_xy_position(x = "LEK")
ggplot(LongCRP, aes(x = LEK, y = CRP, color = Vreme)) +
geom_boxplot() +
stat_pvalue_manual(pairwise.wilcox.CRP, label = "p.adj.signif",
step.increase = 0.03,
bracket.nudge.y = 20) +
theme_minimal() +
ggtitle("Trend opadanja vrednosti CRP-a kod lečenih i nelečenih bolesnika") +
labs(x = "Terapija") +
scale_color_discrete(name = "Vreme\nmerenja CRP-a")
GGplot
Now I know that I can extract p values from my ggplot graph, but I would really want to use tbl_summary() for this.
Thank you for the help!
I am making a plot to show the relationship between house size and prices. The thing is, I need the 5% of the most recently built houses to have a different color and symbol on the plot.
Here is my code (new_baltimore is the dataframe):
y <- new_baltimore$AGE
quantile(y, 0.05) #the result is 4
k <- subset(new_baltimore, y<=4)
kk <- k$SQFT
col = ifelse(any new_baltimore$SQFT %in% kk, "red", "green")
pch = ifelse(any new_baltimore$SQFT %in% kk, 25, 20)
plot(new_baltimore$SQFT, PRICE, col=col, pch=pch)
R gives me the errors
Error: unexpected symbol in "col = ifelse(any new_baltimore"
Error: unexpected symbol in "pch = ifelse(any new_baltimore"
Any help?
edit: This is the reproducible data:
baltimore_struct <-
structure(
list(
new_baltimore.SQFT = c(
11.25,
28.92,
30.62,
26.12,
22.04,
39.42,
21.88,
25.6,
44.12,
19.88,
12.08,
10.99,
12.8,
29.79,
14.3,
13.72,
11.84,
18.06,
10.72,
8.96,
14.38,
36.75,
20,
22.82,
24.86,
19.2,
11.58,
26,
14.4,
11.62,
23.08,
23.76,
15.6,
10,
22.8,
16.76,
22.1,
14.28,
15.36,
16,
23.04,
24.94,
11.82,
12.88,
11.2,
18.12,
38.25,
17.68,
19.02,
32.8,
15.16,
21.975,
12.6,
23.52,
17.52,
47.61,
20.55,
35.52,
8.4,
13.68,
14.48,
12.8,
12.8,
18,
15.4,
10.08,
8.96,
8.96,
20,
12.88,
12,
18.16,
14.28,
26,
12.02,
20.8,
11.78,
8.68,
17.6,
11.4,
44.55,
46.32,
10.24,
9.6,
31.2,
26.4,
13.6,
27.48,
17.86,
18.04,
14.84,
10.46,
14.56,
6.96,
9.5,
11.86,
12.88,
12.32,
6.72,
10.08,
15.6,
6.72,
11.52,
11.76,
10.24,
11.52,
9.28,
6.72,
15.6,
15.5,
9.84,
15.6,
13.76,
10.24,
5.76,
10.08,
11.52,
12.15,
9.77,
15,
14.4,
14.5,
22.54,
10.24,
7.8,
8.4,
10.92,
42.9,
9,
10.5,
10.08,
12.6,
8.96,
8.58,
7.56,
10.8,
13.44,
10.24,
14.44,
12.24,
13.2,
9.6,
15.22,
24.16,
10.24,
10.24,
9.88,
23.2,
17.68,
24.3,
35.94,
21.6,
11.02,
21,
23.92,
14.4,
28,
11.44,
21.94,
10.24,
16.86,
9.92,
13.44,
12,
14.76,
8.96,
11.52,
8.64,
8.12,
11.12,
11.28,
10.36,
11.52,
17.1,
17.52,
10.73,
11.2,
12.8,
12,
41.07,
12.8,
22.36,
10.56,
13.44,
11.02,
17.98,
18.88,
11.76,
9.36,
11.52,
27.3,
23.04,
17.68,
13.36,
11.6,
11.52,
9.98,
12.96,
11.13,
19.6,
11.52,
12.16,
0,
10.64
),
PRICE2 = c(
47,
113,
165,
104.3,
62.5,
70,
127.5,
64.5,
145,
63.5,
58.9,
65,
48,
3.5,
12.8,
17.5,
36,
41.9,
53.5,
24.5,
24.5,
55.5,
60,
51,
46,
46,
44,
54.9,
42.5,
44,
44.9,
37.9,
33,
43.9,
49.6,
52,
37.5,
50,
35.9,
42.9,
107,
112,
44.9,
55,
102,
35.5,
62.9,
39,
110,
8,
62,
85.9,
57,
110,
67.7,
89.5,
70,
74,
13,
48,
24,
53.5,
34.5,
53,
87.5,
33.5,
24,
9.6,
30,
41,
30,
38.9,
20.7,
49.9,
18.6,
39,
34,
16,
18.9,
15.2,
41.5,
53,
22,
24.9,
6.7,
32.5,
30,
59,
29.5,
26,
16.5,
39,
48.9,
33.5,
46,
54,
57.9,
37.9,
32,
31,
34,
29,
32.5,
51.9,
31,
41.8,
48,
28,
35,
46.5,
51.9,
35.4,
16,
35,
35,
36.5,
35.9,
45,
40,
35,
38,
37,
23,
25.5,
39.5,
21.5,
9,
67.5,
13.4,
12.5,
28.5,
23,
33.5,
9,
11,
30.9,
31.65,
33,
33.4,
47,
40,
46,
45.5,
57,
29.9,
30,
34,
51,
64.5,
57.5,
85.5,
61,
38,
56.5,
60.4,
51.5,
54,
69,
56,
27.9,
37.5,
32.9,
22,
29.9,
39.9,
32.6,
38.5,
21.5,
25.9,
27.5,
22.9,
31.5,
8.5,
5.5,
33,
57,
47,
43.5,
43.9,
68.5,
44.25,
61,
40,
44.5,
57,
35,
35.1,
64.5,
40,
42.6,
50,
58,
58,
55,
43,
54,
39,
45,
42,
38.9,
43.215,
26.5,
30,
29.5
)
),
row.names = c(
1L,
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,
27L,
28L,
29L,
30L,
31L,
32L,
33L,
34L,
35L,
36L,
37L,
38L,
39L,
40L,
41L,
42L,
43L,
44L,
45L,
46L,
47L,
48L,
49L,
50L,
51L,
53L,
54L,
55L,
56L,
57L,
58L,
59L,
60L,
61L,
62L,
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,
92L,
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,
118L,
119L,
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,
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
),
class = "data.frame"
)
edit2: I found the error, I just had to remove the any in the ifelse commands. So the correct code looks like this
col = ifelse(new_baltimore$SQFT %in% kk, "red", "green")
pch = ifelse(new_baltimore$SQFT %in% kk, 25, 20)
next time, please try to provide some reproducible data. It makes it easier for others to help you. You can find more information here.
I tried to generate some data on my own. Hope it fits your data. I recommend using the tidyverse as it contains a lot of useful packages for manipulating and visualising data. library(tidyverse) loads all packages from the tidyverse but you can also load only the necessary packages such as dplyr for data manipulation or ggplot2 for data visualisation. See comments for further details:
#install.packages("tidyverse")
library(tidyverse)
# generate some data
data <- data.frame(
age = sample(c(10:50), 100, replace=TRUE),
price = sample(c(50000:1000000), 100, replace=TRUE),
size = sample(c(200:500), 100, replace=TRUE)
)
# save threshold
threshold <- quantile(data$age, 0.05)
plot_data <- data %>%
mutate(groups = factor(ifelse(age<threshold, "newer", "older"))) # mutate generates a new variable in the data and you can define groups based on conditions
ggplot(plot_data,
aes(x=size, y=price, group=groups, color=groups, shape=groups)) + # here you specify the mappings of the aesthetics and group the data depending on the groups variable that corresponds to our threshold
geom_point(size=4) +
scale_color_manual(values = c("aquamarine4","burlywood")) + # control color aesthetic
scale_shape_manual(values = c(18, 19)) + # control shape aesthetic
theme_classic() # this one of a lot of predefined themes
Hope that helps.
I tried to cluster my dataset using K-mean, but there is a categorical data in column 9; so when I ran k-mean it had an error like this:
res<-NbClust(mi[2:9],min.nc=2,max.nc=15,method="ward.D2")
Error in t(jeu) %*% jeu :
requires numeric/complex matrix/vector arguments
So I could only run K-mean for columns from 2 to 8. I wonder if there is another way of clustering the data where I could run with column 9 as well?
Data:
df <- structure(list(Name = structure(c(58L, 188L, 40L, 155L, 32L, 88L, 92L, 55L, 135L, 31L, 139L, 26L, 126L, 10L, 166L, 104L, 75L, 180L, 35L, 175L, 77L, 99L, 4L, 71L, 141L, 176L, 53L, 39L, 172L, 196L, 123L, 107L, 16L, 96L, 82L, 185L, 30L, 15L, 94L, 129L, 187L, 151L, 33L, 23L, 28L, 44L, 157L, 69L, 132L, 83L, 131L, 11L, 182L, 181L, 54L, 115L, 116L, 183L, 150L, 195L, 45L, 144L, 1L, 110L, 17L, 114L, 9L, 117L, 112L, 70L, 34L, 169L, 27L, 66L, 3L, 73L, 133L, 91L, 154L, 130L, 160L, 105L, 90L, 165L, 67L, 100L, 162L, 98L, 29L, 68L, 189L, 192L, 102L, 190L, 134L, 136L, 52L, 12L, 81L, 59L, 63L, 122L, 93L, 109L, 178L, 138L, 5L, 43L, 140L, 95L, 2L, 174L, 76L, 51L, 156L, 60L, 149L, 128L, 177L, 142L, 103L, 7L, 8L, 14L, 164L, 74L, 145L, 148L, 113L, 86L, 108L, 48L, 163L, 6L, 186L, 89L, 36L, 191L, 125L, 120L, 62L, 65L, 124L, 168L, 147L, 79L, 173L, 84L, 193L, 25L, 146L, 121L, 127L, 153L, 13L, 106L, 119L, 161L, 49L, 97L, 101L, 61L, 137L, 24L, 85L, 194L, 78L, 41L, 170L, 47L, 118L, 184L, 179L, 72L, 42L, 111L, 87L, 57L, 38L, 37L, 171L, 22L, 50L, 80L, 159L, 18L, 152L, 64L, 56L, 158L, 167L, 46L, 19L, 21L, 20L, 143L), .Label = c("#Mashtag 2013", "#Mashtag 2014", "#Mashtag 2015", "10 Heads High", "5am Saint", "77 Lager", "AB:02", "AB:03", "AB:04", "AB:06", "AB:08", "AB:10", "AB:11", "AB:13", "AB:15", "AB:17", "AB:18", "AB:20", "Ace Of Chinook", "Ace Of Citra", "Ace Of Equinox", "Ace Of Simcoe", "Albino Squid Assasin", "Alice Porter", "All Day Long - Prototype Challenge", "Alpha Dog", "Alpha Pop", "Amarillo - IPA Is Dead", "American Ale", "Anarchist Alchemist", "Arcade Nation", "Avery Brown Dredge", "Baby Dogma", "Baby Saison - B-Sides", "Bad Pixie", "Barley Wine - Russian Doll", "Barrel Aged Albino Squid Assassin", "Barrel Aged Hinterland", "Berliner Weisse With Raspberries And Rhubarb - B-Sides", "Berliner Weisse With Yuzu - B-Sides", "Bitch Please (w/ 3 Floyds)", "Black Dog", "Black Eye Joe (w/ Stone Brewing Co)", "Black Eyed King Imp", "Black Eyed King Imp - Vietnamese Coffee Edition", "Black Hammer", "Black Jacques", "Black Tokyo Horizon (w/Nøgne Ã\230 & Mikkeller)", "Blitz Berliner Weisse", "Blitz Series", "Born To Die", "Bounty Hunter - Shareholder Brew", "Bourbon Baby", "Bracken's Porter", "Bramling X", "Brewdog Vs Beavertown", "Brixton Porter", "Buzz", "Candy Kaiser", "Cap Dog (w/ Cap Brewery)", "Catherine's Pony (w/ Beavertown)", "Challenger", "Chaos Theory", "Chili Hammer", "Chinook - IPA Is Dead", "Citra", "Clown King", "Cocoa Psycho", "Coffee Imperial Stout", "Comet", "Dana - IPA Is Dead", "Dead Metaphor", "Dead Pony Club", "Deaf Mermaid - B-Sides", "Devine Rebel (w/ Mikkeller)", "Dog A", "Dog B", "Dog C", "Dog D", "Dog E", "Dog Fight (w/ Flying Dog)", "Dog Wired (w/8 Wired)", "Dogma", "Doodlebug", "Double IPA - Russian Doll", "Edge", "El Dorado - IPA Is Dead", "Electric India", "Ella - IPA Is Dead", "Elvis Juice V2.0 - Prototype Challenge", "Everday Anarchy", "Fake Lager", "Galaxy", "Goldings - IPA Is Dead", "Growler", "Hardcore IPA", "Hardkogt IPA", "HBC 366 - IPA Is Dead", "HBC 369", "Hello My Name Is Beastie", "Hello My Name Is Holy Moose", "Hello My Name Is Ingrid", "Hello My Name Is Little Ingrid", "Hello My Name Is Mette-Marit", "Hello My Name Is PaÌ\210ivi", "Hello My Name is Sonja (w/ Evil Twin)", "Hello My Name is Vladimir", "Hello My Name Is ZeÌ\201 (w/ 2Cabeças)", "Hinterland", "Hobo Pop", "Hop Fiction - Prototype Challenge", "Hopped-Up Brown Ale - Prototype Challenge", "Hoppy Christmas", "Hops Kill Nazis", "Hunter Foundation Pale Ale", "Hype", "India Session Lager - Prototype Challenge", "International Arms Race (w/ Flying Dog)", "Interstellar", "Jack Hammer", "Jasmine IPA", "Jet Black Heart", "Kohatu - IPA Is Dead", "Konnichiwa Kitsune", "Libertine Black Ale", "Libertine Porter", "Lichtenstein Pale Ale", "Lizard Bride - Prototype Challenge", "Lost Dog (w/Lost Abbey)", "Lumberjack Stout", "Magic Stone Dog (w/Magic Rock & Stone Brewing Co.)", "Mandarina Bavaria - IPA Is Dead", "Mango Gose - B-Sides", "Melon And Cucumber IPA - B-Sides", "Misspent Youth", "Morag's Mojito - B-Sides", "Moshi Moshi 15", "Motueka", "Movember", "Mr.Miyagi's Wasabi Stout", "Nanny State", "Nelson Sauvin", "Neon Overlord", "Never Mind The Anabolics", "No Label", "Nuns With Guns", "Old World India Pale Ale", "Old World Russian Imperial Stout", "Orange Blossom - B-Sides", "Pale - Russian Doll", "Paradox Islay", "Paradox Islay 2.0", "Paradox Jura", "Peroxide Punk", "Pilsen Lager", "Pioneer - IPA Is Dead", "Prototype 27", "Prototype Helles", "Prototype Pils 2.0", "Pumpkin King", "Punk IPA 2007 - 2010", "Punk IPA 2010 - Current", "Restorative Beverage For Invalids And Convalescents", "Rhubarb Saison - B-Sides", "Riptide", "Russian Doll â\200“ India Pale Ale", "Rye Hammer", "San Diego Scotch Ale (w/Ballast Point)", "Santa Paws", "Shareholder Black IPA 2011", "Ship Wreck", "Shipwrecker Circus (w/ Oskar Blues)", "Simcoe", "Sink The Bismarck!", "Skull Candy", "Sorachi Ace", "Sorachi Bitter - B-Sides", "Spiced Cherry Sour - B-Sides", "Stereo Wolf Stout - Prototype Challenge", "Storm", "Sub Hop", "Sunk Punk", "Sunmaid Stout", "Sunshine On Rye - B-Sides", "The Physics", "This. Is. Lager", "TM10", "Trashy Blonde", "Truffle and Chocolate Stout - B-Sides", "U-Boat (w/ Victory Brewing)", "Vagabond Pale ALe - Prototype Challenge", "Vagabond Pilsner", "Vic Secret", "Waimea - IPA Is Dead", "Whisky Sour - B-Sides", "Zephyr"), class = "factor"), ABV = c(4.5, 4.1, 4.2, 6.3, 7.2, NA, 4.7, 7.5, 7.3, 5.3, 4.5, 4.5, 6.1, 11.2, 6, 8.2, 12.5, 8, 4.7, 3.5, 15, 6.7, 7.8, 6.7, 0.5, 7.5, 5.8, 3.6, 10.5, 12.5, 7.2, 8.2, 10.7, 9.2, 7.1, 5, 16.5, 12.8, 6.7, 10, NA, 10, 4.5, 7.4, 7.2, 9.5, 9.2, 9, 7.2, 7.5, NA, 10.43, 7.1, 8, 5, 5.4, 4.1, 10.2, 4, 7, 12.7, 6.5, 7.5, 4.2, 11.8, 7.6, 15, 4.4, 6.3, 7.2, NA, 4.5, 4.5, 7.5, 10, 3.8, 6.4, NA, 4, 15.2, 5.4, 8.3, 6.5, 8, 12, 8.2, 5.6, 7.2, 6.3, 10, 5.6, 4.5, 8.2, 8.4, 6, 6.7, 6.5, 11.5, 8.5, 5.2, 7.1, 4.7, 6.7, 9, 6.5, 6.7, 5, 5.8, 7.5, 4.5, 9, 41, 15, 8.5, 7.2, 9, 3.8, 5.7, 6.3, 7.5, 4.4, 18, 10.5, 11.3, NA, 5.2, 4.5, 9.5, 7.2, 2.7, 6.4, 17.2, 8.5, 4.9, 4.7, 7.2, 10, 4.5, 7.2, 7.2, 6.7, 7.2, 4.4, 9, 7.5, 16.1, 6.7, 2.5, 7.4, 2.8, 4.2, 5.8, 5.2, 10, 12.8, 8.3, 6.5, 6, 3, 7.6, 5.5, 8.8, 5.2, 5.2, 8, 6.7, 15, 11.5, 7.1, NA, 7.5, 7.2, 5.2, 6.8, 5.5, 5.2, 6.7, 5, 9, 9.2, 13.8, 4.5, 3.2, 16.1, 4.7, 14.2, 13, 7.2, 9.2, 4.9, 7.2, 7.2, 4.5, 4.5, 4.5, 7.6), IBU = c(60, 41.5, 8, 55, 59, 38, 40, 75, 30, 60, 50, 42, 45, 150, 70, 70, 100, 60, 45, 33, 90, 67, 70, 70, 55, 75, 35, 8, 85, 125, 70, 70, 100, 125, 65, 47, 20.5, 50, 70, 35, 20, 55, 35, 65, 70, 85, 149, 65, 100, 30, 30, 65, 68, 35, 50, 35, 65, 50, 35, 20, 85, 35, 50, 50, 80, 70, 80, 35, 85, 70, 9, 35, 30, 70, 85, 35, 40, 45, 40, 20, 20, 70, 60, 45, 85, 42, 40, 70, 55, 85, 30, 55, 42, 50, 50, 40, 35, 80, 65, 45, 90, 45, 67, 85, 20, 67, 30, 40, 90, 38, 50, 1085, 90, 85, 100, 80, 20, 35, 130, 75, 35, 70, 14, 50, 25, 65, 25, 80, 70, 36, 50, 75, 100, 30, 37, 100, 80, 55, 50, 250, 67, 100, 70, 70, 80, 85, 70, 35, 70, 30, 25, 40, 50, 55, 70, 70, 55, 60, 8, 175, 35, 40, 45, 55, 85, 70, 90, 50, 80, 45, 0, 130, 55, 30, 60, 40, 70, 50, 85, 65, 60, 40, 8, 100, 25, 20, 100, 250, 50, 18, 250, 250, 40, 40, 40, 70), OG = c(1044, 1041.7, 1040, 1060, 1069, 1045, 1046, 1068, 1079, 1052, 1047, 1046, 1067, 1098, 1058, 1076, 1093, 1082, 1047, 1038, 1120, 1013, 1074, 1066, 1007, 1068, 1049, 1040, 1102, 1087, 1067, 1076, 1105, 1085, 1065, 1048.5, 1112, 1096, 1066, 1080, 1048, 1090, 1048, 1069, 1067, 1095, 1083, 1080, 1064, 1080, 1043, 1095, 1056, 1077, 1049, 1050, 1042, 1026, 1041, 1081, 1113.5, 1050, 1070, 1042, 1096, 1073, 1113, 1040, 1063, 1067, 1032, 1048, 1045, 1068, 1098, 1040, 1057, 1081, 1039, 1110, 1055, 1076, 1060, 1075, 1130, 1078, 1055, 1067, 1060, 1098, 1058, 1046, 1078, 1080, 1050, 1063, 1068, 1096, 1078, 1049, 1067, 1055, 1013, 1094, 1060, 1013, 1050, 1053, 1072, 1042.9, 1084, 1085, 1120, 1072, 1064, 1083, 1039, 1053, 1060, 1068, 1045, 1150, 1093, 1098, 1052, 1048, 1043, 1075, 1067, 1033, 1061, 1156, 1068, 1047, 1043, 1064, 1097, 1045, 1068, 1065, 1064, 1064, 1045, 1090, 1069, 1125, 1063, 1027, 1069, 1032.5, 1044, 1060, 1050, 1128, 1108, 1076, 1059, 1056, 1007, 1072, 1053, 1084, 1048, 1053, 1074, 1066, 1120, 1104, 1067, 1089, 1069, 1065, 1052, 1068, 1062, 1048, 1066, 1053, 1094, 1069, 1088, 1045, 1007, 1015, 1008, 1025, 1015, 1065, 1016, 1010, 1065, 1065, 1045, 1045, 1045, 1067), EBC = c(20, 15, 8, 30, 10, 15, 12, 22, 120, 200, 140, 62, 219, 70, 25, NA, 36, 12, 8, 50, 100, 19, 90, 30, 30, 30, 44, NA, 64, 40, 30, 16, 300, 40, 13, 65, 20, 111, 30, 80, 14, 300, 40, 60, 30, 250, 19.5, 97, 12, 46, 15, 23, 14, 15, 110, 11.5, 17, 197, 45, 12, 250, 23, 40, 30, 115, 59, 400, 12, 24, 30, 2, 44, 25, 30, 130, 25, 10, 15, 18, 158, 30, 30, 25, 240, 24, 90, 15, 30, 30, 30, 54, 25, 70, 200, 8, 15, 250, 115, 31.2, 45, 15, 200, 19, 400, NA, 19, 60, 177.3, 200, 18, 20, 40, 100, 15, 12, 180, 6, 25, 14, 30, 30, 57, NA, 164, 10, 16, 10, 195, 30, 57, 20, 128, 15, 12, 10, 12, 65, 20, 150, 15, 19, 12, 30, 190, 50, 400, 30, 10, 30, 42, 19, 35, 17, 300, 79, 30, 50, 17, 9, 40, 25, 190, 35, 165, 35, 30, 100, 38, 71, 15, 50, 14, 200, 86, 230, 13, 30, 200, 400, 60, 25, 18, 8, 500, 25, 67, 300, 15, 78.8, 13, 17, 104, 18, 18, 18, 20), PH = c(4.4, 4.4, 3.2, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.2, 5.2, 4.4, 4.4, 4.4, 5.2, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 3.2, 4.4, 4.4, 4.4, 4.4, 4.3, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.2, 4.4, 4.4, 4.2, 4.4, 4.4, 4.4, 4.4, 4.4, 4.5, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 5.2, 3.2, 5.2, 4.4, 4.4, 4.4, 5.2, 4.4, 4, 4.4, 4.2, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 3.5, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 5.2, 5.2, 4.2, 4.4, 4.4, 4.2, 4.4, 4.4, 4.4, 4.3, 3.2, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 5.2, 5.2, 4.4, 5.2, 4.4, 4.4, 4.4, 4.4, 4.4, 5.2, 5.2, 4.2, 4.5, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.2, 4.4, 4.4, 4.2, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.3, 4.4, 4.2, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 3.2, 4.4, 4.4, 4.5, 4.4, 5.2, 5.2, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 5.2, 5.2, 4.4, 4.4, 4.4, 4.4, 4.4, 4.3, 4.2, 4.4, 4.2, 3.2, 4.4, 4.2, 4, 4.4, 4.4, 4.2, 4.2, 4.4, 4.4, 4.2, 4.2, 4.2, 4.4), AttenuationLevel = c(75, 76, 83, 80, 67, 88.9, 78, 80.9, 74.7, 77, 74.5, 72.8, 70.1, 87, 79.3, 83, 68, 86, 79, 68.4, 98, 79.7, 79.7, 77.3, 28.6, 82.1, 90, 83, 102, 81.2, 82.1, 83, 76.2, 81.2, 85, 79.4, 100, 79.17, 77.3, 85, 89.6, 84.4, 72.9, 82.6, 82.1, 76.8, 83, 76, 84, 70, 81.4, 83.2, 82.1, 79.2, 79, 84, 76.2, 74.5, 75.6, 74, 76.8, 76, 81.4, 76.2, 79.2, 79.5, 84.1, 79.5, 82.6, 82.1, 88, 72.9, 75.6, 82.1, 79.6, 70, 87, 93.8, 76.9, 82, 74.6, 82.9, 83.3, 81.3, 102.3, 83.3, 78, 82.1, 80, 70, 74, 73.9, 83.3, 81.3, 87, 84, 70.6, 79.2, 84.6, 81.6, 80.6, 70, 79.7, 73.4, 87, 79.7, 76, 84.9, 79.2, 81, 82.1, 81.2, 98, 90.3, 84, 83.1, 87, 79.3, 83, 82.1, 73.3, 93.3, 80, 79.6, 87, 79, 79.1, 81.3, 82.1, 70.8, 80.3, 80.8, 95.6, 80.7, 83.7, 84, 79.4, 73.9, 78.6, 84.6, 79.7, 84, 82.9, 80, 82.6, 84, 81, 70.4, 82.6, 63.1, 72.7, 76.7, 80, 89, 81.5, 82.9, 81.4, 82.14, 82.5, 80.6, 79.3, 79.8, 77.1, 75.5, 82.4, 77.3, 98, 85, 79, 94.4, 81.1, 87, 73.1, 76.5, 67.7, 79.2, 77.3, 73.6, 73.4, 82.6, 83, 75.6, 78, 84, 75.6, 75.6, 84.4, 84.6, 81, 78.7, 84.6, 84.6, 75.6, 75.6, 75.6, 82), FermentationTempCelsius = c(19L, 18L, 21L, 9L, 10L, 22L, 10L, 19L, 19L, 19L, 19L, 22L, 18L, 17L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 18L, 19L, 19L, 19L, 19L, 21L, 21L, 21L, 19L, 21L, 21L, 21L, 9L, 19L, 20L, 21L, 19L, 19L, 22L, 21L, 19L, 18L, 19L, 18L, 19L, 19L, 19L, 12L, 23L, 21L, 10L, 9L, 19L, 19L, 19L, 21L, 19L, 19L, 18L, 18L, 21L, 19L, 20L, 20L, 21L, 10L, 19L, 19L, 21L, 19L, 19L, 19L, 21L, 19L, 20L, 23L, 19L, 21L, 19L, 21L, 19L, 20L, 21L, 21L, 19L, 19L, 19L, 21L, 19L, 9L, 22L, 14L, 20L, 19L, 19L, 20L, 18L, 14L, 19L, 19L, 19L, 21L, 20L, 19L, 19L, 19L, 21L, 10L, 21L, 21L, 19L, 18L, 19L, 21L, 20L, 17L, 20L, 19L, 19L, 22L, 19L, 20L, 20L, 19L, 15L, 19L, 19L, 19L, 19L, 21L, 21L, 10L, 12L, 19L, 21L, 19L, 19L, 21L, 19L, 19L, 20L, 21L, 22L, 21L, 99L, 19L, 19L, 22L, 16L, 19L, 19L, 21L, 18L, 21L, 19L, 19L, 19L, 21L, 17L, 21L, 19L, 19L, 19L, 19L, 19L, 21L, 19L, 23L, 19L, 20L, 19L, 19L, 19L, 19L, 19L, 19L, 21L, 18L, 21L, 19L, 21L, 21L, 12L, 21L, 21L, 21L, 21L, 12L, 21L, 21L, 19L, 19L, 19L, 21L), Yeast = structure(c(1L, 1L, 1L, 3L, 3L, 4L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 3L, 1L, 2L, 2L, 1L, 2L, 4L, 2L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 3L, 4L, 2L, 3L, 3L, 1L, 1L, 2L, 2L, 1L, 2L, 2L, 1L, 2L, 1L, 2L, 2L, 2L, 3L, 1L, 1L, 4L, 1L, 1L, 1L, 2L, 1L, 1L, 4L, 1L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 3L, 2L, 3L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 2L, 3L, 2L, 2L, 2L, 2L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 2L, 4L, 1L, 1L, 2L, 1L, 1L, 1L, 2L, 2L, 3L, 3L, 1L, 2L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 3L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 4L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 2L, 1L, 1L, 2L, 3L, 2L, 2L, 2L, 2L, 3L, 2L, 2L, 1L, 1L, 1L, 2L), .Label = c("Wyeast 1056 - American Ale", "Wyeast 1272 - American Ale II", "Wyeast 2007 - Pilsen Lager", "Wyeast 3711 - French Saison"), class = "factor")), class = "data.frame", row.names = c(NA, -196L))
df
To solve your specific issue, you can generate dummy variables to run your desired clustering.
One way to do it is using the dummy_columns() function from the fastDummies package.
library(fastDummies)
df_dummy <- dummy_columns(df, select_columns = "Yeast", remove_selected_columns = TRUE)
res <- NbClust(df_dummy[2:9], min.nc = 2, max.nc = 15, method = "ward.D2")
As noted in the comments, the better practices for conduncting clustering analysis are more questions for CrossValidated.
Problem
I quite like the overall presentation of the density plots and QQ plots in the package ggpubr. I would like to plot three density plots and three QQ plots on the same plot window using the functions ggdensity() and ggqqplot.
I used par(mfrow=c(2,3) to create the preferred plot arrangement; however, I cannot figure out why this function will not plot the figures as specified. Instead, the code is plotting one plot per plot window.
Would anyone be able to lend a hand? Many thanks if this is possible.
R-code:
par(mfrow=c(2,3))
library("ggpubr")
#Density Plots
ggdensity(Sapflow$Temperature, main="Density of Temperature (°C)", xlab="Temperature °C")
ggdensity(Sapflow$Radiation, main="Density of Radiation", xlab=expression(paste("Radiation W m"^{-2}*"s"^{-1})))
ggdensity(Sapflow$Humidity...., main="Density of Relative Humidity (%)", xlab="Relative Humdity (%)")
#Q-Q Plots
ggqqplot(Sapflow$Temperature, main="Density of Temperature (°C)", xlab="Temperature °C")
ggqqplot(Sapflow$Radiation, main="Density of Radiation", xlab=expression(paste("Radiation W m"^{-2}*"s"^{-1})))
ggqqplot(Sapflow$Humidity, main="Density of Relative Humidity (%)", xlab="Relative Humdity (%)")
Example
The code is plotting one plot per plot window instead of 2 rows and 3 columns using par(mfrow=c(2,3))
Data
structure(list(Date = structure(c(31L, 42L, 53L, 55L, 56L, 57L,
58L, 59L, 60L, 32L, 33L, 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L,
43L, 44L, 45L, 46L, 47L, 48L, 49L, 50L, 51L, 52L, 54L, 61L, 72L,
83L, 86L, 87L, 88L, 89L, 90L, 91L, 62L, 63L, 64L, 65L, 66L, 67L,
68L, 69L, 70L, 71L, 73L, 74L, 75L, 76L, 77L, 78L, 79L, 80L, 81L,
82L, 84L, 85L, 92L, 103L, 114L, 117L, 118L, 119L, 120L, 121L,
122L, 93L, 94L, 95L, 96L, 97L, 98L, 99L, 100L, 101L, 102L, 104L,
105L, 106L, 107L, 108L, 109L, 110L, 111L, 112L, 113L, 115L, 116L,
123L, 134L, 145L, 147L, 148L, 149L, 150L, 151L, 152L, 124L, 125L,
126L, 127L, 128L, 129L, 130L, 131L, 132L, 133L, 135L, 136L, 137L,
138L, 139L, 140L, 141L, 142L, 143L, 144L, 146L, 1L, 12L, 23L,
25L, 26L, 27L, 28L, 29L, 30L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L,
10L, 11L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 24L
), .Label = c("10/1/18", "10/10/18", "10/11/18", "10/12/18",
"10/13/18", "10/14/18", "10/15/18", "10/16/18", "10/17/18", "10/18/18",
"10/19/18", "10/2/18", "10/20/18", "10/21/18", "10/22/18", "10/23/18",
"10/24/18", "10/25/18", "10/26/18", "10/27/18", "10/28/18", "10/29/18",
"10/3/18", "10/30/18", "10/4/18", "10/5/18", "10/6/18", "10/7/18",
"10/8/18", "10/9/18", "6/1/18", "6/10/18", "6/11/18", "6/12/18",
"6/13/18", "6/14/18", "6/15/18", "6/16/18", "6/17/18", "6/18/18",
"6/19/18", "6/2/18", "6/20/18", "6/21/18", "6/22/18", "6/23/18",
"6/24/18", "6/25/18", "6/26/18", "6/27/18", "6/28/18", "6/29/18",
"6/3/18", "6/30/18", "6/4/18", "6/5/18", "6/6/18", "6/7/18",
"6/8/18", "6/9/18", "7/1/18", "7/10/18", "7/11/18", "7/12/18",
"7/13/18", "7/14/18", "7/15/18", "7/16/18", "7/17/18", "7/18/18",
"7/19/18", "7/2/18", "7/20/18", "7/21/18", "7/22/18", "7/23/18",
"7/24/18", "7/25/18", "7/26/18", "7/27/18", "7/28/18", "7/29/18",
"7/3/18", "7/30/18", "7/31/18", "7/4/18", "7/5/18", "7/6/18",
"7/7/18", "7/8/18", "7/9/18", "8/1/18", "8/10/18", "8/11/18",
"8/12/18", "8/13/18", "8/14/18", "8/15/18", "8/16/18", "8/17/18",
"8/18/18", "8/19/18", "8/2/18", "8/20/18", "8/21/18", "8/22/18",
"8/23/18", "8/24/18", "8/25/18", "8/26/18", "8/27/18", "8/28/18",
"8/29/18", "8/3/18", "8/30/18", "8/31/18", "8/4/18", "8/5/18",
"8/6/18", "8/7/18", "8/8/18", "8/9/18", "9/1/18", "9/10/18",
"9/11/18", "9/12/18", "9/13/18", "9/14/18", "9/15/18", "9/16/18",
"9/17/18", "9/18/18", "9/19/18", "9/2/18", "9/20/18", "9/21/18",
"9/22/18", "9/23/18", "9/24/18", "9/25/18", "9/26/18", "9/27/18",
"9/28/18", "9/29/18", "9/3/18", "9/30/18", "9/4/18", "9/5/18",
"9/6/18", "9/7/18", "9/8/18", "9/9/18"), class = "factor"), Temperature = c(85.07,
79.72, 72.83, 90.1, 83.02, 73.34, 77.11, 74.79, 81.66, 77.71,
66.14, 78.15, 69.33, 68.13, 60.31, 69.47, 81.86, 78.63, 77.69,
77.56, 52.88, 53.32, 53.74, 55.85, 49.56, 55.3, 69.25, 74.96,
69.29, 60.07, 54.31, 48.6, 55.73, 56.74, 47.66, 60.51, 55.64,
58.39, 63.8, 63.16, 73.65, 71.08, 64.34, 60.1, 51.61, 54.87,
58.23, 52.49, 52.56, 59.64, 67.85, 64.42, 60.08, 59.71, 57.12,
58.7, 68.85, 72.44, 89.13, 77.67, 62.17, 61.3, 63.58, 66.26,
60.09, 56.63, 53.11, 59.84, 60.06, 80.76, 79.51, 73.96, 84.58,
78.77, 71.65, 72.59, 77.52, 69.04, 78.26, 77.22, 73.75, 81.95,
82.04, 78.14, 73.41, 72.76, 90.68, 74.24, 71.3, 74.4, 60.26,
66.08, 65.18, 57.17, 66.88, 75.53, 71.52, 74.97, 66.02, 78.06,
73.58, 68.18, 83.55, 80.4, 66.28, 72.32, 72.39, 77.74, 69.81,
74.21, 77.37, 88.28, 65.33, 87.54, 80.49, 69.58, 68.18, 69.25,
60.06, 66.38, 68.51, 71.65, 63.29, 76.63, 80.46, 85.56, 81.25,
94.48, 73.87, 76.8, 72.83, 77.55, 81.5, 77.7, 75.79, 94.38, 99.55,
94.14, 87.29, 84.81, 82.63, 85.27, 84.52, 71.13, 76.28, 78.06,
82.83, 75.18, 83.8, 85.38, 84, 85.33), Humidity = c(19.67, 18.82,
20.38, 14.94, 12.92, 15.28, 15.12, 16.05, 15.19, 16.67, 18.69,
14.61, 16.71, 17.35, 16.98, 15.44, 15.21, 18.62, 20.11, 18.64,
15.66, 17.2, 18.21, 19.32, 23.02, 21.69, 18.03, 18.46, 18.45,
20.78, 23.04, 22.05, 19.71, 20.59, 24.89, 23.34, 24.7, 24.2,
22.43, 18.21, 17.66, 18.23, 20.36, 22.83, 23.52, 22.88, 19.59,
21.51, 22.25, 21.47, 22.03, 22.51, 25.54, 24.01, 24.28, 26.21,
23.72, 17.63, 17.27, 19.19, 19.97, 19.84, 22.78, 24.46, 23.05,
23.31, 24.75, 23.23, 18.91, 15.56, 13.51, 15.8, 17.67, 19.18,
18.93, 20.05, 17.1, 16.87, 18.77, 20.49, 21.5, 18.04, 18.82,
17.38, 13.05, 13.13, 13.48, 16.32, 16.74, 16.11, 15.77, 15.48,
18.17, 18.16, 18.44, 16.63, 16.64, 14.47, 13.07, 14.14, 17.27,
16.71, 18.22, 12.9, 13.95, 14.7, 15.78, 17.52, 19.66, 18.87,
18.07, 16.4, 12.92, 10.57, 10.04, 9.78, 10.24, 14.25, 15.92,
11.59, 9.25, 10.33, 11.22, 15.03, 13.67, 14.26, 15.42, 8.34,
8.56, 12.37, 14.38, 15.47, 16.4, 17.15, 20.05, 11.08, 10.63,
14.34, 13.27, 9.33, 8.1, 10.95, 12.79, 8.64, 11.42, 12.12, 9.91,
7.86, 3.51, 4.97, 3.63, 5.59), Radiation = c(197.8, 195.5, 288,
72, 160.5, 337.1, 176.9, 242.3, 189.4, 295.7, 363.2, 158, 290,
251.2, 297.3, 192.6, 163.5, 274.5, 210.7, 243.4, 287.4, 375.7,
290.5, 336.4, 361.6, 369.2, 302.6, 295.2, 348.5, 343.5, 327.6,
358.9, 358.6, 288.9, 325.6, 307.8, 321.3, 321.5, 280.6, 264.9,
253, 279.5, 318.1, 285.1, 330.8, 252, 201, 229.9, 259.3, 230.4,
265.5, 214.1, 307, 311.1, 282.5, 256.9, 227.2, 263.4, 68.2, 130.8,
276.6, 299.2, 276.5, 243.9, 291, 289.3, 290.6, 259.6, 220.5,
72.7, 158.9, 233.8, 105.9, 164.2, 168.1, 188.7, 120.1, 217.7,
111.2, 114.7, 143.6, 55.2, 108.5, 162.2, 185, 197.7, 54.1, 126.3,
111.2, 135.4, 228.3, 214.3, 240.1, 247.6, 173, 172.4, 131.9,
149.4, 203.1, 92.3, 168.5, 146.6, 65.9, 103.6, 200.2, 131.3,
183.5, 128.3, 140.6, 124.1, 125.9, 75.8, 173.2, 47.9, 111.7,
205.8, 188.3, 175.6, 193.7, 170.4, 188.3, 108, 171.1, 59.5, 87.7,
142.2, 111.8, 26.3, 129.9, 103.1, 158.7, 147.9, 109.8, 67.8,
106.6, 12.3, 15.8, 53, 63.4, 86.2, 123.3, 112.9, 128.2, 141.9,
81.6, 102, 86.8, 83.9, 50, 96.8, 100.5, 47), Sapflow = c(14.97,
16.31, 17.52, 7.45, 12.18, 15.82, 11.79, 14.45, 10.95, 13.62,
16.28, 11.42, 16.13, 15.09, 17.28, 14.43, 11.7, 16.06, 17.66,
16.33, 17.79, 18.58, 19.41, 19.8, 21.63, 21.35, 17.81, 17.56,
19.37, 21.27, 23.26, 23.67, 22.64, 21.85, 24.81, 22.36, 24.72,
23.87, 23.67, 22.01, 19.23, 19.92, 21.99, 23.6, 24.9, 24.46,
22.22, 23.95, 24.81, 23.88, 22.98, 24.47, 26.09, 25.97, 25.82,
26.24, 25.09, 22, 16.91, 21.35, 25.32, 25.76, 26.38, 25.78, 25.77,
25.15, 26.29, 26.22, 24.59, 18.26, 18.91, 21.57, 21.37, 21.29,
23.96, 24.85, 21.02, 23.05, 22.69, 23.9, 25.24, 25.4, 23.19,
22.8, 22.08, 21.86, 13.82, 22.05, 23.21, 20.12, 22.73, 21.88,
23.33, 24.76, 23.5, 22.06, 22.01, 20.65, 21.54, 19.9, 21.67,
21.84, 18.82, 17.99, 21.41, 23.53, 23.39, 25.75, 22.62, 22.25,
21.81, 16.81, 20.42, 12.08, 12.36, 15.31, 14.14, 15.48, 15.18,
14.19, 12.09, 12.39, 12.34, 12.61, 10.79, 10.53, 11.29, 9.92,
9.79, 10.86, 10.98, 10.58, 12.54, 12.52, 12.25, 6.38, 0.91, 5.24,
6.56, 5.72, 4.55, 4.99, 2.88, 0.99, 1.03, 1.57, 2.07, 2.3, 2.22,
2.11, 2.21, 2.29)), class = "data.frame", row.names = c(NA, -152L
))
After further reading, I found a function called plot_grid() from the cowplot package.
Answer:
#Arrange all the plots onto one page
plot_grid(den1, den2, den3, qq1, qq2, qq3,
labels=c("A", "B", "C", "D", "E", "F"),
ncol=3, nrow=2)
Results:
I want to make 20000 sample from a data which is quite big,based on the each value size in order to fill the NA values:
so I use the output of histogram, but it wasn't successful, and get me an error, how to avoid it ?
y=hist(maindata,col="red",breaks=length(unique(maindata))
for(k in 1:20000){
data=maindata
for(i in 1:nrow(data)){
if (data[i]="Na"){
data[i]=sample(y$breaks,size=1,replace=FALSE,prob=y$density)}}}
I get this error :
Error in sample.int(length(x), size, replace, prob) :
incorrect number of probabilities
and I check the length(y$breaks) and length(y$density),length(y$breaks) was one unit more, how should I fixed it ?
thank you in advance
EDIT :
structure(list(breaks = c(15, 16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87,
88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102,
103, 104, 105, 106, 107, 108, 109), counts = c(27L, 17L, 31L,
83L, 118L, 144L, 211L, 279L, 354L, 312L, 300L, 377L, 407L, 443L,
481L, 351L, 302L, 236L, 248L, 178L, 141L, 101L, 77L, 80L, 63L,
44L, 64L, 44L, 60L, 46L, 24L, 29L, 15L, 28L, 21L, 13L, 19L, 10L,
30L, 11L, 12L, 12L, 7L, 12L, 12L, 11L, 11L, 7L, 7L, 4L, 4L, 4L,
1L, 2L, 3L, 6L, 1L, 1L, 3L, 3L, 0L, 0L, 0L, 1L, 1L, 0L, 0L, 0L,
1L, 0L, 0L, 1L, 0L, 1L, 0L, 1L, 0L, 1L, 1L, 0L, 0L, 1L, 1L, 0L,
0L, 0L, 0L, 0L, 3L, 0L, 0L, 0L, 1L, 2L), density = c(0.00453172205438067,
0.00285330647868412, 0.00520308828465928, 0.0139308492782813,
0.0198053037932192, 0.0241691842900302, 0.035414568647197, 0.0468277945619335,
0.0594159113796576, 0.0523665659617321, 0.0503524672708963, 0.0632762672037596,
0.0683115139308493, 0.0743538100033568, 0.0807317891910037, 0.0589123867069486,
0.0506881503860356, 0.0396106075864384, 0.0416247062772743, 0.0298757972473985,
0.0236656596173212, 0.0169519973145351, 0.0129237999328634, 0.0134273246055723,
0.0105740181268882, 0.00738502853306479, 0.0107418596844579,
0.00738502853306479, 0.0100704934541793, 0.0077207116482041,
0.0040281973816717, 0.00486740516951997, 0.00251762336354481,
0.00469956361195032, 0.00352467270896274, 0.00218194024840551,
0.00318898959382343, 0.00167841557569654, 0.00503524672708963,
0.0018462571332662, 0.00201409869083585, 0.00201409869083585,
0.00117489090298758, 0.00201409869083585, 0.00201409869083585,
0.0018462571332662, 0.0018462571332662, 0.00117489090298758,
0.00117489090298758, 0.000671366230278617, 0.000671366230278617,
0.000671366230278617, 0.000167841557569654, 0.000335683115139308,
0.000503524672708963, 0.00100704934541793, 0.000167841557569654,
0.000167841557569654, 0.000503524672708963, 0.000503524672708963,
0, 0, 0, 0.000167841557569654, 0.000167841557569654, 0, 0, 0,
0.000167841557569654, 0, 0, 0.000167841557569654, 0, 0.000167841557569654,
0, 0.000167841557569654, 0, 0.000167841557569654, 0.000167841557569654,
0, 0, 0.000167841557569654, 0.000167841557569654, 0, 0, 0, 0,
0, 0.000503524672708963, 0, 0, 0, 0.000167841557569654, 0.000335683115139308
), mids = c(15.5, 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
24.5, 25.5, 26.5, 27.5, 28.5, 29.5, 30.5, 31.5, 32.5, 33.5, 34.5,
35.5, 36.5, 37.5, 38.5, 39.5, 40.5, 41.5, 42.5, 43.5, 44.5, 45.5,
46.5, 47.5, 48.5, 49.5, 50.5, 51.5, 52.5, 53.5, 54.5, 55.5, 56.5,
57.5, 58.5, 59.5, 60.5, 61.5, 62.5, 63.5, 64.5, 65.5, 66.5, 67.5,
68.5, 69.5, 70.5, 71.5, 72.5, 73.5, 74.5, 75.5, 76.5, 77.5, 78.5,
79.5, 80.5, 81.5, 82.5, 83.5, 84.5, 85.5, 86.5, 87.5, 88.5, 89.5,
90.5, 91.5, 92.5, 93.5, 94.5, 95.5, 96.5, 97.5, 98.5, 99.5, 100.5,
101.5, 102.5, 103.5, 104.5, 105.5, 106.5, 107.5, 108.5), xname = "b",
equidist = TRUE), .Names = c("breaks", "counts", "density",
"mids", "xname", "equidist"), class = "histogram")
Data information :
> head(maindata)
[1] 30 44 -1 32 30 34
> is.numeric(maindata)
[1] TRUE
> is.vector(maindata)
[1] TRUE
> length(maindata)
[1] 36203
Do you just want 20,000 samples from the distribution of the non-missing data? If so, another way to approach this would be to just calculate a kernel density estimate directly from the non-missing data and then sample from that. For example, using fake data:
# Fake data with some missing values
set.seed(31)
dat = rnorm(30000, 20, 10)
dat[sample(1:30000, 5000)] = NA
# Create kernel density estimate from the data
# n is the number of grid points used in the esimate (should always be a power of 2)
dat.dens = density(dat[!is.na(dat)], n=2^10)
sim.sample = sample(dat.dens$x, 2e4, replace=TRUE, prob=dat.dens$y)
plot(dat.dens)
lines(density(sim.sample), col="red")
Please let me know if I've misunderstood what you're trying to do.