我的代码必须非常接近,但似乎有些小事情已经关闭。
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
我的数据集看起来像这样。
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种不同的记录。
我从下面的链接中得到了这个想法,我认为这非常有帮助。
答案 0 :(得分:0)
我基本上使用以下代码。
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
)
只有在我将负值更改为正数后才能工作。我不知道为什么所有的数据点都需要是积极的。我要调查一下。无论如何,这是一个非常好的工具,可以保存在一个工具箱中。
答案 1 :(得分:-1)
有趣的是,treemap
在提供给索引的列名称中不接受下划线(_),因此,请对所有带有下划线的列进行重命名。