Here is my data spe.ch.method
:
spe.ch.method <-
structure(list(merge = structure(c(-7L, -38L, -19L, -6L, -13L,
-2L, -8L, -23L, -36L, -10L, -29L, -25L, -16L, -3L, -35L, -22L,
-32L, 4L, 12L, -9L, 16L, -14L, 10L, 3L, -26L, 18L, -21L, 20L,
24L, 15L, 9L, 25L, 27L, 22L, 33L, 35L, 34L, -4L, -24L, -33L,
-37L, -17L, -20L, -1L, -18L, 1L, -12L, -5L, 6L, 5L, -34L, 11L,
-11L, -15L, 14L, 7L, 2L, -27L, 13L, 19L, 21L, -30L, 8L, -31L,
26L, 17L, 23L, -28L, 31L, 28L, 30L, 29L, 32L, 36L), .Dim = c(37L,
2L)), height = c(0.00636619772367553, 0.00636619772367597, 0.00954929658551418,
0.0127323954473515, 0.0127323954473516, 0.0159154943091897, 0.0222816920328652,
0.0222816920328652, 0.0294042077558286, 0.0381971863420549, 0.0477464829275686,
0.0679972304353541, 0.0771860453590509, 0.101859163578813, 0.108428016099619,
0.130507053335355, 0.155971844230057, 0.207072752716134, 0.222727472454222,
0.231558136077153, 0.244422476970328, 0.284589332450292, 0.368020665934361,
0.410114423448918, 0.448816939519144, 0.46521909140276, 0.611154981472878,
0.781981287058179, 0.9474918022082, 1.04498838881851, 1.14095631913861,
1.71533296271409, 2.22787742308588, 2.23744457877555, 4.11682456910057,
8.82355004501468, 16.2866428471926), order = c(14L, 16L, 13L,
17L, 35L, 29L, 5L, 10L, 12L, 25L, 2L, 20L, 8L, 1L, 21L, 31L,
9L, 38L, 24L, 6L, 37L, 3L, 34L, 23L, 18L, 19L, 33L, 22L, 11L,
27L, 32L, 15L, 26L, 30L, 36L, 7L, 4L, 28L), labels = c("CB1",
"CB2", "CB3", "CB4", "CB5", "CB6", "CB7", "CB8", "CB9", "CB10",
"CB11", "CB12", "CB13", "CB14", "CB15", "CB16", "CB17", "CB18",
"CB19", "CB20", "CC1", "CC2", "CC3", "CC4", "CC5", "CC6", "CC7",
"CC8", "CC9", "CC10", "CC11", "CC12", "CC13", "CC14", "CC15",
"CC16", "CC17", "CC18"), method = "ward.D2", call = hclust(d = spe.ch,
method = clstrMethod), dist.method = "euclidean"), class = "hclust")
And here is example data res.hc
:
res.hc <-
structure(list(merge = structure(c(-15L, -13L, -14L, -23L, -36L,
-20L, -37L, -19L, -46L, -41L, -26L, -1L, -35L, -24L, -21L, -12L,
5L, -43L, -34L, -4L, -10L, -7L, -11L, -22L, -17L, 12L, -33L,
-5L, -3L, -25L, 10L, 8L, -6L, -39L, -8L, 18L, 17L, -9L, 22L,
25L, 31L, 26L, 33L, 35L, 40L, -2L, 41L, 43L, 47L, -29L, -32L,
-16L, -49L, 3L, -31L, -47L, 1L, -50L, -48L, -27L, -18L, -38L,
-40L, -30L, 11L, 13L, 2L, -45L, 9L, -42L, 4L, -44L, 6L, 20L,
21L, 14L, -28L, 24L, 7L, 19L, 16L, 28L, 15L, 34L, 29L, 23L, 36L,
37L, 30L, 32L, 27L, 38L, 39L, 44L, 42L, 45L, 46L, 48L), .Dim = c(49L,
2L)), height = c(0.205853857157348, 0.350218756601623, 0.42877117242016,
0.494083187830451, 0.530325907996572, 0.535389255696797, 0.593534342646989,
0.645715762772523, 0.703830908172413, 0.71088117569639, 0.738993588868799,
0.772222449786047, 0.778129827091505, 0.786567350290742, 0.797764154308547,
0.828693622706567, 0.841289957946828, 0.845769739265785, 0.982485681621528,
0.997103491446316, 1.01222520768599, 1.03545970319198, 1.07097197299987,
1.08009876392544, 1.09186240041721, 1.13143510536774, 1.18268909786155,
1.19682607716751, 1.21173556211688, 1.25027523499501, 1.27168083812686,
1.33295040067908, 1.39885947095838, 1.46683777170002, 1.62304947693353,
1.64485743320623, 1.6585735917931, 1.85379841079867, 1.86498009205068,
2.26302421304787, 2.29522869690842, 2.33746531357676, 2.44585996576722,
2.47488073347208, 3.08834296946717, 3.2554325818601, 4.40054164699477,
4.42007357714693, 6.07664156265458), order = c(41L, 48L, 34L,
45L, 19L, 15L, 29L, 12L, 26L, 27L, 17L, 4L, 46L, 50L, 25L, 37L,
47L, 8L, 39L, 21L, 30L, 7L, 23L, 49L, 36L, 14L, 16L, 35L, 38L,
11L, 44L, 6L, 5L, 28L, 9L, 43L, 13L, 32L, 3L, 22L, 20L, 31L,
2L, 1L, 18L, 10L, 42L, 33L, 24L, 40L), labels = c("Alabama",
"Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut",
"Delaware", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois",
"Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine",
"Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi",
"Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire",
"New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota",
"Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island",
"South Carolina", "South Dakota", "Tennessee", "Texas", "Utah",
"Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin",
"Wyoming"), method = "complete", call = hclust(d = dist(df)),
dist.method = "euclidean"), class = "hclust")
When I run as below:
fviz_dend(spe.ch.method, #or data is res.hc
cex = 0.5,
k =2
,rect = TRUE,
,rect_fill= TRUE
,rect_border = c("red","blue")
)
There are two results. One using data of res.hc
is ok.
But another one using data of spe.ch.method
is an error and without image output. Error: Aesthetics must be either length 1 or the same as the data (4): color and fill
.
Hope someone help me. Thank you very much.