2017-08-10 91 views
1

我期待做出某種比例平方(由於缺乏一個更好的名字)可視化R.例如:GGPLOT2比例廣場

Billion Dollar O-gram

如何做到這一點R中的任何意見(最好GGPLOT2)?

+0

學習如何使用樹地圖包也可能有助於你的情節轉換成GGPLOT2,爲便於與格式化之後。請參閱:https://stackoverflow.com/questions/42866566/converting-treemap-to-ggplot – jesstme

回答

4

這種類型的可視化被稱爲樹形圖。適當地,您可以使用treemap包。你可以找到treemaphere的詳細教程,但我會告訴你的基本知識。下面我向你展示如何在ggplot2中創建一個樹形圖。

樹形包

library(treemap) 

cars <- mtcars 
cars$carname <- rownames(cars) 

treemap(
    cars, 
    index = "carname", 
    vSize = "disp", 
    vColor = "cyl", 
    type = "value", 
    format.legend = list(scientific = FALSE, big.mark = " ") 
) 

The output of the treemap function

GGPLOT2

還有GitHub上使用ggplot2創建樹狀發育包。 Here's the repo用於安裝包裝。

library(tidyverse) 
library("ggfittext") 
library("treemapify") 

cars <- mtcars 
cars$carname <- rownames(cars) 
cars <- mutate(cars, cyl = factor(cyl)) 

ggplot(cars, aes(area = disp, fill = cyl, label = carname)) + 
    geom_treemap() + 
    geom_treemap_text(
    fontface = "italic", 
    colour = "white", 
    place = "centre", 
    grow = TRUE 
) 

enter image description here

+0

非常好的安德魯! – ryguy72

+0

謝謝@ ryguy72! –