如何在r中绘制treemap / choropleth?闪亮的应用程序

问题描述 投票:0回答:1

我试图绘制一个交互式树形图来描绘基于不同日期输入的库存移动

原始数据 :

sraw <- structure(list(Date = c("2018-02-28", "2018-02-28", "2018-02-28", 
"2018-02-28", "2018-02-28", "2018-02-28"), Category = c("Bakery ", 
"Household ", "Household ", "Personal care", "Personal care", 
"Breakfast "), Sub_Category = c("Wafers ", "laundry ", "Pet Care", 
"Womens grooming ", "Womens grooming ", "Instant food"), Product 
= c("strawbery", 
"washing powder ", "Cat food ", "sanitary pad ", "sanitary pad ", 
"Noodles "), Brand = c("NO BRAND", "wheel ", "Whiskars", "whisper", 
"whisper", "Yipee"), Day = c(28L, 28L, 28L, 28L, 28L, 28L), Month = c(2L, 
2L, 2L, 2L, 2L, 2L), Year = c(2018L, 2018L, 2018L, 2018L, 2018L, 
2018L), MRP = c("5", "48", "160", "34", "40", "45"), Quantity = c(2, 
1, 1, 1, 1, 1), Sales = c(10, 48, 160, 34, 40, 45), Wday = c("Wednesday", 
"Wednesday", "Wednesday", "Wednesday", "Wednesday", "Wednesday"
), Week = c(9L, 9L, 9L, 9L, 9L, 9L), X = c(NA, NA, NA, NA, NA, 
NA), X. = c(NA, NA, NA, NA, NA, NA)), .Names = c("Date", "Category", 
"Sub_Category", "Product", "Brand", "Day", "Month", "Year", "MRP", 
"Quantity", "Sales", "Wday", "Week", "X", "X."), row.names = 870158:870163, 
class = "data.frame")

我一直在干扰树图,但没有任何积极的东西:

  treeMapCoordinates <- treemapify(sraw,
                                 area = sraw$Quantity,
                                 fill = sraw$Category,
                                 label = sraw$Sub_Category,
                                 group = sraw$Category)

treeMapPlot <- ggplotify(treeMapCoordinates) + 
  scale_x_continuous(expand = c(0, 0)) +
  scale_y_continuous(expand = c(0, 0)) +
  scale_fill_brewer(palette = "Dark2")

print(treeMapPlot)

但这显示错误。 :

treemapify出错(sraw,area = sraw $ Quantity,fill = sraw $ Category,:unused arguments(fill = sraw $ Category,label = sraw $ Sub_Category,group = sraw $ Category)

有人可以帮我这个吗?

谢谢

r ggplot2 shiny treemap dygraphs
1个回答
0
投票

似乎包已更新,其中一些功能已被弃用。您可以尝试使用相同的数据(使用相同的数据):

library(devtools)
install_github("wilkox/treemapify")
ggplot2::ggplot(sraw, ggplot2::aes(area = Quantity,
                                   fill = Category,
                                   label = Sub_Category,
                                   group = Category)) + geom_treemap()

这将给你以下情节:

enter image description here

您提供的Shiny没有输入或为了一个等值线图。

© www.soinside.com 2019 - 2024. All rights reserved.