使用treemapify在R中绘制树图

时间:2016-05-16 17:11:45

标签: r ggplot2 treemap

我正在使用名为treemapify的非常酷的库创建一些数据的树形图,其中可以找到详细信息here和github存储库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")

1 个答案:

答案 0 :(得分:2)

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

scale_fill_brewer(palette = "Greens")