Closed datalorax closed 3 years ago
Daniel! Sorry for the criminally slow response. Too many balls in the air ATM...
Ya, that looks like a bug. I've still got some pressing tasks to clear off of my plate, but will bookmark and get back to it once things calm down a bit.
Not a worry! It's nothing pressing at all, from my end. Just thought you'd want to know. 🙂
Should add: I'm pretty sure you're correct about the single level. Should be easy enough to catch/fix if you feel up for a PR in the meantime ;-) https://github.com/grantmcdermott/parttree/blob/master/R/parttree.R#L101
I am fairly swamped until the end of the term (as I'm sure you are) but I may be able to find a few moments to look into it more. Will submit a PR if I do.
Hey Daniel, should be sorted in the dev version. Thanks for the hint about single levels; made it an easy fix!
library(ggplot2)
library(rpart)
library(parttree)
mpg$drv <- as.factor(mpg$drv)
drv_stump <- rpart(drv ~ displ + cty, mpg,
control = list(maxdepth = 1))
ggplot(mpg, aes(displ, cty, fill = drv)) +
geom_parttree(data = drv_stump,
alpha = 0.4,
flipaxes = TRUE) +
geom_point(aes(color = drv))
Created on 2020-12-17 by the reprex package (v0.3.0)
P.S. Note that I'm setting aes(... fill = drv)
in the initialising ggplot() call above, since this way it retains all the factor levels for the legend. An alternative would be to use drop = FALSE
in the scales, but this seems easier...
Looks great! Thanks Grant!
Hi Grant,
I'm trying out your parttree package for the first time and overall I'm really liking it. I did run into what seems to be a bug with
flipaxes
though. In the below, you can see that it has no effect. I haven't dug into the code at all but I'm wondering if it could be related to having a model that is missing a level altogether in its prediction?I can, of course, manually flip the x/y axes. But I just wanted to make you aware.
Created on 2020-11-06 by the reprex package (v0.3.0)