相关疑难解决方法(0)

用ggplot2重现晶格树状图

这有可能用ggplot2重现这个格子图吗?

library(latticeExtra)
data(mtcars)
x  <- t(as.matrix(scale(mtcars)))
dd.row <- as.dendrogram(hclust(dist(x)))
row.ord <- order.dendrogram(dd.row)

dd.col <- as.dendrogram(hclust(dist(t(x))))
col.ord <- order.dendrogram(dd.col)

library(lattice)

levelplot(x[row.ord, col.ord],
      aspect = "fill",
      scales = list(x = list(rot = 90)),
      colorkey = list(space = "left"),
      legend =
      list(right =
           list(fun = dendrogramGrob,
                args =
                list(x = dd.col, ord = col.ord,
                     side = "right",
                     size = 10)),
           top =
           list(fun = dendrogramGrob,
                args =
                list(x = dd.row,
                     side = "top",
                     size = 10))))
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

graphics r ggplot2 lattice ggdendro

35
推荐指数
2
解决办法
2万
查看次数

标签 统计

ggdendro ×1

ggplot2 ×1

graphics ×1

lattice ×1

r ×1