简体   繁体   中英

The leaf's labels aren't showing completely when I use as.dendrogram

When I plot the dendrogram using "as.dendrogram" all the leaf labels are cut. See those linked images below as examples:

When I plot using "hclust" (all labels showing correctly) Dendrogram 1

When I plot using "as.dendrogram" Dendrogram 2

Codes:

The data I created just to show the problem

test <- matrix(c(34,34,32,27,12,1,2,1,1,1), ncol=2)
colnames(test) <- c('Variable1', 'Variable2')
rownames(test) <- c('African Forest Elephant', 'Asian Domestic Elephant','African White Rhino','West African Giraffe','African Mountain Gorilla')
test_table <- as.table(test)

To plot the first linked image

hctest = hclust(dist(test_table))
plot(hctest, axes = FALSE)

The second one

hctest = as.dendrogram(hctest)
plot(hctest, edge.root = TRUE, horiz = TRUE)

PS: If I use "horiz = FALSE" the same problem persists. I tried exporting the image and also tried using R markdown, but nothing changes.

You can fix this with par by adjusting the plot margins mar=c(bottom, left, top, right) . (Defaults are c(5, 4, 4, 2) + 0.1 ).

par(mar=c(5, 4, 4, 10) + 0.1)
plot(hctest, edge.root=TRUE, horiz=TRUE)

在此处输入图片说明

Data

hctest <- structure(list(structure(5L, members = 1L, height = 0, label = "African Mountain Gorilla", leaf = TRUE), 
    structure(list(structure(4L, members = 1L, height = 0, label = "West African Giraffe", leaf = TRUE), 
        structure(list(structure(3L, members = 1L, height = 0, label = "African White Rhino", leaf = TRUE), 
            structure(list(structure(1L, label = "African Forest Elephant", members = 1L, height = 0, leaf = TRUE), 
                structure(2L, label = "Asian Domestic Elephant", members = 1L, height = 0, leaf = TRUE)), members = 2L, midpoint = 0.5, height = 1)), members = 3L, midpoint = 0.75, height = 2.23606797749979)), members = 4L, midpoint = 0.875, height = 7.07106781186548)), members = 5L, midpoint = 0.9375, height = 22.0227155455452, class = "dendrogram")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM