{"action":"created","issue":{"url":"https://api.github.com/repos/hadley/ggplot2/issues/1380","labels_url":"https://api.github.com/repos/hadley/ggplot2/issues/1380/labels{/name}","comments_url":"https://api.github.com/repos/hadley/ggplot2/issues/1380/comments","events_url":"https://api.github.com/repos/hadley/ggplot2/issues/1380/events","html_url":"https://github.com/hadley/ggplot2/issues/1380","id":112323199,"number":1380,"title":"setup_data() method fail in geom_text","user":{"login":"GuangchuangYu","id":626539,"avatar_url":"https://avatars.githubusercontent.com/u/626539?v=3","gravatar_id":"","url":"https://api.github.com/users/GuangchuangYu","html_url":"https://github.com/GuangchuangYu","followers_url":"https://api.github.com/users/GuangchuangYu/followers","following_url":"https://api.github.com/users/GuangchuangYu/following{/other_user}","gists_url":"https://api.github.com/users/GuangchuangYu/gists{/gist_id}","starred_url":"https://api.github.com/users/GuangchuangYu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GuangchuangYu/subscriptions","organizations_url":"https://api.github.com/users/GuangchuangYu/orgs","repos_url":"https://api.github.com/users/GuangchuangYu/repos","events_url":"https://api.github.com/users/GuangchuangYu/events{/privacy}","received_events_url":"https://api.github.com/users/GuangchuangYu/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-10-20T09:24:51Z","updated_at":"2015-10-20T11:34:53Z","closed_at":"2015-10-20T11:34:53Z","body":"[subsetting](http://ygc.name/2015/09/24/subsetting-data-in-ggtree/) is commonly used in visualizing phylogenetic tree.\r\n\r\nWith the new feature of `setup_data()` function, I have sucessfully over-write the method for performing [subsetting](http://ygc.name/2015/09/24/subsetting-data-in-ggtree/) with previous github version of ggplot2.\r\n\r\nHere is my implementation, which support `aes(subset=X)`\r\n```r\r\n\r\ngeom_text2 <- function(mapping = NULL, data = NULL, stat = \"identity\",\r\n  position = \"identity\", parse = FALSE, show.legend = NA, inherit.aes = TRUE,\r\n  ..., nudge_x = 0, nudge_y = 0, check_overlap = FALSE)\r\n{\r\n  if (!missing(nudge_x) || !missing(nudge_y)) {\r\n    if (!missing(position)) {\r\n      stop(\"Specify either `position` or `nudge_x`/`nudge_y`\", call. = FALSE)\r\n    }\r\n\r\n    position <- position_nudge(nudge_x, nudge_y)\r\n  }\r\n\r\n  layer(\r\n    data = data,\r\n    mapping = mapping,\r\n    stat = stat,\r\n    geom = GeomTextGGtree,\r\n    position = position,\r\n    show.legend = show.legend,\r\n    inherit.aes = inherit.aes,\r\n    params = list(\r\n      parse = parse,\r\n      check_overlap = check_overlap,\r\n      ...\r\n    )\r\n  )\r\n}\r\n\r\n##' @importFrom ggplot2 GeomText\r\n##' @importFrom ggplot2 draw_key_text\r\nGeomTextGGtree <- ggproto(\"GeomTextGGtree\", GeomText,\r\n                          setup_data = function(data, params) {\r\n                              data[data$subset,]\r\n                          },\r\n                          \r\n                          draw_panel = function(data, panel_scales, coord, parse = FALSE,\r\n                              na.rm = FALSE, check_overlap = FALSE) {\r\n                              GeomText$draw_panel(data, panel_scales, coord, parse,\r\n                                                  na.rm, check_overlap)\r\n                          },\r\n\r\n                          required_aes = c(\"x\", \"y\", \"label\"),\r\n                          \r\n                          default_aes = aes(colour = \"black\", size = 3.88, angle = 0, hjust = 0.5,\r\n                              vjust = 0.5, alpha = NA, family = \"\", fontface = 1, lineheight = 1.2),\r\n                          \r\n                          draw_key = draw_key_text\r\n                          )\r\n```\r\n\r\nI update ggplot2 today and found that my implementation fail to work.\r\n\r\nIt do work for `segment`, but fail for both `text` and `point`.\r\n\r\n```r\r\nggtree(rtree(30)) + geom_segment2(aes(subset=isTip, x=x+1, yend=y), xend=10)\r\n```\r\n\r\n![screenshot 2015-10-20 17 24 15](https://cloud.githubusercontent.com/assets/626539/10603217/6db2184c-774f-11e5-8a99-c96cd449a128.png)\r\n\r\n```r\r\n> ggtree(rtree(30)) + geom_segment2(aes(subset=isTip, x=x+1, yend=y), xend=10) + geom_text2(aes(subset=isTip, label=label))\r\nError: is.logical(na.rm) is not TRUE\r\n> traceback()\r\n13: stop(sprintf(ngettext(length(r), \"%s is not TRUE\", \"%s are not all TRUE\"),\r\n        ch), call. = FALSE, domain = NA)\r\n12: stopifnot(is.logical(na.rm))\r\n11: remove_missing(data, params$na.rm, c(self$required_aes, self$non_missing_aes),\r\n        snake_class(self))\r\n10: f(..., self = self)\r\n9: self$geom$handle_na(data, self$geom_params)\r\n8: f(..., self = self)\r\n7: l$draw_geom(d, panel, plot$coordinates)\r\n6: (function (l, d)\r\n   l$draw_geom(d, panel, plot$coordinates))(dots[[1L]][[4L]], dots[[2L]][[4L]])\r\n5: mapply(FUN = f, ..., SIMPLIFY = FALSE)\r\n4: Map(function(l, d) l$draw_geom(d, panel, plot$coordinates), plot$layers,\r\n       data)\r\n3: ggplot_gtable(data)\r\n2: print.ggplot(x)\r\n1: function (x, ...)\r\n   UseMethod(\"print\")(x)\r\n```\r\n\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/hadley/ggplot2/issues/comments/149534149","html_url":"https://github.com/hadley/ggplot2/issues/1380#issuecomment-149534149","issue_url":"https://api.github.com/repos/hadley/ggplot2/issues/1380","id":149534149,"user":{"login":"hadley","id":4196,"avatar_url":"https://avatars.githubusercontent.com/u/4196?v=3","gravatar_id":"","url":"https://api.github.com/users/hadley","html_url":"https://github.com/hadley","followers_url":"https://api.github.com/users/hadley/followers","following_url":"https://api.github.com/users/hadley/following{/other_user}","gists_url":"https://api.github.com/users/hadley/gists{/gist_id}","starred_url":"https://api.github.com/users/hadley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hadley/subscriptions","organizations_url":"https://api.github.com/users/hadley/orgs","repos_url":"https://api.github.com/users/hadley/repos","events_url":"https://api.github.com/users/hadley/events{/privacy}","received_events_url":"https://api.github.com/users/hadley/received_events","type":"User","site_admin":false},"created_at":"2015-10-20T11:34:53Z","updated_at":"2015-10-20T11:34:53Z","body":"You need to always pass `na.rm` in the `layer()` args - you might want to re-look at the extending ggplot2 vignette."}}