3

I try to replicate this circle packing example in R: Visualizing hierarchical data with circle packing in ggplot2? on my own data, but I bumped into a problem that I could not comprehend.

The data is:

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)

I want to ultimately draw a circle packing demonstrating the number of people following each religion. The replication derived from the link at the beginning is:

indexList <- c("Group", "Religion")
treedat <- treemap(df, index= indexList, vSize="Number",
               type="value", fun.aggregate="sum", palette="RdYlBu")

The error is :

Error in do.call("format", args.legend) : second argument must be a list

Could somebody explain to me what I did wrong?

My Khe
  • 43
  • 4

1 Answers1

0

I cannot tell you exactly why this is happening as I am not familiar with these methods, but your syntax is fine.

However the data seems to fall below some minimum standards.

Correcting a type in "Islamm" and adding in one more value for group number and Religion fixes it for me:

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")

enter image description here

user1317221_G
  • 15,087
  • 3
  • 52
  • 78
  • Thanks. There is a problem with your answer though. When I try to change the elements in group Islam to 1 : "Christianity 1", "Christianity 2", "Buddhism 1", "Buddhism 2", "Islam" or to 3 elements : "Christianity 1", "Christianity 2", "Buddhism 1", "Buddhism 2", "Islam", "Islam", "Islam", the same error pops up. I do not see why all the groups must have the same number of elements. Please tell me what you think. – My Khe Feb 06 '18 at 13:21