我尝试在我自己的数据中复制R:Visualizing hierarchical data with circle packing in ggplot2?中的这个圆形包装示例,但我碰到了一个我无法理解的问题。
数据是:
Religion <- c("Christianity 1", "Christianity 2", "Buddhism 1", "Buddhism 2", "Islam")
Number <- c(1, 1, 2, 3, 2)
Group <- c("Christian", "Christian", "Buddhism", "Buddhism", "Islammm")
df <- data.frame(Religion, Number, Group)
我想最终绘制一个圆圈包装,展示每个宗教信仰后的人数。从开头的链接派生的复制是:
indexList <- c("Group", "Religion")
treedat <- treemap(df, index= indexList, vSize="Number",
type="value", fun.aggregate="sum", palette="RdYlBu")
错误是:
Error in do.call("format", args.legend) : second argument must be a list
有人可以向我解释我做错了吗?
答案 0 :(得分:0)
我不能确切地告诉你为什么会这样,因为我不熟悉这些方法,但你的语法很好。
然而,数据似乎低于某些最低标准。
纠正'#34; Islamm&#34;并为group
number
和Religion
添加一个值,以便为我修复:
Religion <- c("Christianity 1", "Christianity 2",
"Buddhism 1", "Buddhism 2", "Islam","Islam")
# typo and extra entry
Number <- c(1, 1, 2, 3, 2, 100)
# extra number
Group <- c("Christian", "Christian", "Buddhism",
"Buddhism", "Islam","Islam")
# extra entry
df <- data.frame(Religion, Number, Group)
indexList <- c("Group", "Religion")
treedat <- treemap(df, index= indexList, vSize="Number",
type="value", fun.aggregate="sum", palette="RdYlBu")