Skip to content

@mapping must be <ggplot2::mapping> #700

@DrDinhLuong

Description

@DrDinhLuong

Dear YuLab-SMU

When I run code below

#--------------------------------
nwk <- system.file("extdata", "sample.nwk", package="treeio")

tree <- read.tree(nwk)
circ <- ggtree(tree, layout = "circular")

df <- data.frame(first=c("a", "b", "a", "c", "d", "d", "a",
"b", "e", "e", "f", "c", "f"),
second= c("z", "z", "z", "z", "y", "y",
"y", "y", "x", "x", "x", "a", "a"))
rownames(df) <- tree$tip.label

df2 <- as.data.frame(matrix(rnorm(39), ncol=3))
rownames(df2) <- tree$tip.label
colnames(df2) <- LETTERS[1:3]

p1 <- gheatmap(circ, df, offset=.8, width=.2,
colnames_angle=95, colnames_offset_y = .25) +
scale_fill_viridis_d(option="D", name="discrete\nvalue")

library(ggnewscale)
p2 <- p1 + new_scale_fill()
gheatmap(p2, df2, offset=15, width=.3,
colnames_angle=90, colnames_offset_y = .25) +
scale_fill_viridis_c(option="A", name="continuous\nvalue")
#--------------------------------------------------------------

Error: object properties are invalid:

  • @mapping must be ggplot2::mapping, not S3<data.frame>
  1. stop(msg, call. = FALSE)
  2. validate(object)
  3. S7::props<-(*tmp*, value = [[<-(S7::props(x), i, value))
  4. $<-.ggplot2::gg(*tmp*, "mapping", value = structure(list(
    from = structure(1:2, levels = c("first", "second"), class = "factor"),
    to = c(62.4, 68), y = c(0, 0), .panel = structure(c(1L, 1L
    ), class = "factor", levels = "Tree")), row.names = c(1L, ...
  5. $<-(*tmp*, "mapping", value = structure(list(from = structure(1:2, levels = c("first",
    "second"), class = "factor"), to = c(62.4, 68), y = c(0, 0),
    .panel = structure(c(1L, 1L), class = "factor", levels = "Tree")), row.names = c(1L,
    14L), class = "data.frame"))
  6. ggplot_add.new_aes(object, p, objectname)
  7. ggplot_add(object, p, objectname)
  8. add_ggplot(e1, e2, e2name)
  9. method(+, list(ggplot2::ggplot, class_any))(e1 = ,
    e2 = structure("fill", class = "new_aes"), ...)
  10. S7::S7_dispatch()
  11. base_ops[[.Generic]](e1, e2)
  12. doTryCatch(return(expr), name, parentenv, handler)
  13. tryCatchOne(expr, names, parentenv, handlers[[1L]])
  14. tryCatchList(expr, classes, parentenv, handlers)
  15. tryCatch(return(base_ops[[.Generic]](e1, e2)), S7_error_method_not_found = function(cnd) cnd)
  16. Ops.S7_object(p1, new_scale_fill())
  17. Please help me fix problems.

    Thank you so much.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions