m-jahn / WeightedTreemaps

Create Voronoi and Sunburst Treemaps from Hierarchical data
GNU General Public License v3.0
47 stars 9 forks source link

could not find function "asMethod" #19

Closed lcamVz closed 3 years ago

lcamVz commented 3 years ago

I am running the tutorial and came across an error any suggestions?

devtools::install_github("m-jahn/SysbioTreemaps")

library(SysbioTreemaps)

# load example data
data(mtcars)
mtcars$car_name = gsub(" ", "\n", row.names(mtcars))

mtcars$gear  <- as.factor(mtcars$gear)
  dataframeName$colName <- as.factor(datataframeName$colName)

# generate treemap; set seed to obtain same pattern every time
tm <- voronoiTreemap(
  data = mtcars,
  levels = "gear",
  cell_size = "wt",
  shape = "rounded_rect",
  seed = 123
)

I get this error: Error in asMethod(object) : could not find function "asMethod"

m-jahn commented 3 years ago

This error message is most likely triggered by the methods package, one of the dependencies. It supplies the as() function used to coerce polygon coordinates into gpc.poly objects. So much for the background although I'm not 100% sure. I can't reproduce the error because I can't detach methods and see if that package triggers the error. You could try to update your R installation to the latest version and/or update your packages, particularly methods.

m-jahn commented 3 years ago

Alternatively, if you can't install the package for some reason, you can try to use the ShinyTreemaps app which provides the same functionality but with a GUI: https://m-jahn.shinyapps.io/ShinyTreemaps/

lcamVz commented 3 years ago

Thank you for the quick reply. I was able to update the packages and it worked. I tried the shiny app but got an error in the app the table. Maybe is the table format I am presenting the data. I want to use this package to illustrate microbial composition from a data set I have. Any suggestions?

m-jahn commented 3 years ago

Good to hear that the update solved your issue with the package. For the app, try to format your table as a plain and simple *.csv file, that means comma separated values, not tab-separated values. The following example works just fine to generate a csv table and upload it to the app:

library(tidyverse)

df <- data.frame(col1 = letters, col2 = abs(rnorm(length(letters))))
write_csv(df, "test.csv")
lcamVz commented 3 years ago

Thank you! I got the package to work with my data set. Now for some reason, I have a layering issue with one of the level names. It looks like I have a dual text where I don't.

image

Also how I can plot columns removing the zeroes how would you manage that?

m-jahn commented 3 years ago

Regarding overplotting of labels, is it possible that you are plotting two levels, not just one? Like first the parent level which is all "Acidobacteria" and then the next lower level with the different subgroups. The solution here is to simply not plot the parent layer (not necessary if it's all the same group), or don't plot the label for that. You can control which labels to plot using the label_level parameter. In your example, drawing labels for only 2nd level works like this:

drawTreemap(tm, label_level = 2)

Regarding the second question, can you be more specific about what you mean with removing zeroes? For filtering and formatting your data frame I'd suggest to look at some basic tutorials for dplyr and tidyr. These are popular packages to reshape your data.

lcamVz commented 3 years ago

Thank you for the replies! I was able to get the figures and work with the 0. Thank you again!!