使用 treemapify 在 R 中绘制树图

Plotting a Tree Map in R using treemapify

我正在使用一个名为 treemapify 的非常酷的库制作一些数据的树状图,可以在其中找到详细信息 here and github repository here

根据我对文档的阅读,它似乎是基于 ggplot2 的,因此应该可以使用图形语法修改图形

下面是我的代码,其中包含一些虚构的数据。最终结果非常好,但我想使用 scale_colour_brewer 行将配色方案更改为更微妙的颜色。该图运行良好,但配色方案似乎被忽略了。有没有人有这方面的经验?

# Create Random Data
country <- c("Ireland","England","France","Germany","USA","Spain")
job <- c("IT","SOCIAL","Project Manager","Director","Vice-President")

mydf <- data.frame(countries = sample(country,100,replace = TRUE),
               career = sample(job,100,replace=TRUE),
               participent = sample(1:100, replace = TRUE)
)

# Set Up the coords
treemap_coords <- treemapify(mydf, 
                         area="participent", 
                         fill="countries", 
                         label="career", 
                         group="countries")

# Plot the results using the Green Pallete
ggplotify(treemap_coords, 
      group.label.size.factor = 2,
      group.label.colour = "white",
      label.colour = "black",
      label.size.factor = 1) + 
  labs(title="Work Breakdown") +
  scale_colour_brewer(palette = "Greens")

如果您想更改矩形的填充颜色,请尝试 fill 的比例,而不是 colour 的比例:

scale_fill_brewer(palette = "Greens")