Попытка создать древовидную карту, но получение сообщения о неверных именах столбцов - PullRequest
0 голосов
/ 25 апреля 2018

Мой код должен быть довольно близок, но какая-то мелочь кажется отключенной.

library(treemap)

mydata = read.csv("C:\\Users\\rschuell\\Desktop\\top_10.csv")

products <- unique(mydata$product, incomparables = FALSE)

treemap(mydata, #Your data frame object
        index=products,  #A list of your categorical variables
        vSize = reportable_amount,  #This is your quantitative variable
        type="index", #Type sets the organization and color scheme of your treemap
        palette = "Reds",  #Select your color palette from the RColorBrewer presets or make your own.
        title="TreeMap of Products and Amounts", #Customize your title
        fontsize.title = 14 #Change the font size of the title
        )

Я получаю это сообщение об ошибке:

Error in treemap(mydata, index = products, vSize = reportable_amount,  : 
  <index> contains invalid column names

Мой набор данных выглядит такthis.

product asofdate    reportable_amount
CreditFacilities    3/30/2018   29918501.83
CreditFacilities    3/30/2018   50000000
CreditFacilities    3/30/2018   40000000
CreditFacilities    3/30/2018   13766666.67
CreditFacilities    3/30/2018   75000000
CreditFacilities    3/30/2018   40000000
CreditFacilities    3/30/2018   9450000
CreditFacilities    3/30/2018   91287458.38
CreditFacilities    3/30/2018   -81498.17
CreditFacilities    3/30/2018   50000000
DerivativePayables  3/30/2018   -294715.28
DerivativePayables  3/30/2018   -304222.22
DerivativePayables  3/30/2018   -294715.28
DerivativePayables  3/30/2018   -275701.39
DerivativePayables  3/30/2018   -106689.44
DerivativePayables  3/30/2018   -285208.33
DerivativePayables  3/30/2018   -137850.69
DerivativePayables  3/30/2018   -275701.39
DerivativePayables  3/30/2018   -285208.33
DerivativePayables  3/30/2018   -147357.64
DerivativeReceivables   3/30/2018   280264.06
DerivativeReceivables   3/30/2018   144964.17
DerivativeReceivables   3/30/2018   309256.89
DerivativeReceivables   3/30/2018   289928.33
DerivativeReceivables   3/30/2018   289928.33
DerivativeReceivables   3/30/2018   299592.61
DerivativeReceivables   3/30/2018   140132.03
DerivativeReceivables   3/30/2018   37698.8
DerivativeReceivables   3/30/2018   299592.61
DerivativeReceivables   3/30/2018   154628.44

У меня одна дата, продукт повторяется несколько раз, и есть 326 разных записей.

Я получил идею по ссылке ниже, которая, на мой взгляд, была довольно полезной.

https://rpubs.com/brandonkopp/creating-a-treemap-in-r

1 Ответ

0 голосов
/ 25 апреля 2018

Я в основном получил его работать со следующим кодом.

library(treemap)
mydata = read.csv("C:\\Users\\rschuell\\Desktop\\all_pids.csv")

treemap(mydata, #Your data frame object
        index= "PID",  #A list of your categorical variables
        vSize = "Mar",  #This is your quantitative variable
    type="index",        
    palette = "Reds",  #Select your color palette from the RColorBrewer presets or make your own.
        title="TreeMap of Products and Amounts", #Customize your title
        fontsize.title = 14 #Change the font size of the title
        )

Это сработало только после того, как я изменил отрицательные значения на положительные. Я не знаю, почему все данные должны быть положительными. Я должен разобраться в этом. Во всяком случае, это очень хороший инструмент, чтобы держать его в своем наборе инструментов.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...