3

In R Markdown, I would like to plot a decision tree horizontally, so that it fits better the entire PDF page. This code plots it vertically:

```{r, message=FALSE, warning = FALSE, echo=FALSE, cache = FALSE}

rpart.lrn <- makeLearner("classif.rpart", predict.type = "prob", fix.factors.prediction = FALSE) 
model = train(rpart.lrn, task = classif.task, subset = train.set)
tree <- getLearnerModel(model)
rpart.plot(tree) # visualise the tree
```

How can I plot it horizontally instead?

zx8754
  • 52,746
  • 12
  • 114
  • 209
Javide
  • 2,477
  • 5
  • 45
  • 61
  • 1
    `ggplot2` has that option, I don't have a tree model to test this on but trying to create a ggplot object from your plot and adding the `coord_flip` function to it might work. and example can be seen [here](http://www.sthda.com/english/wiki/ggplot2-rotate-a-graph-reverse-and-flip-the-plot) – Dror Bogin May 30 '18 at 10:43
  • 1
    Have you tried so set fig.height and fig.width, for example `{r ggpair, echo=FALSE, message = FALSE, warning = FALSE, fig.height = 12, fig.width = 12}` – PhilippPro May 30 '18 at 11:45
  • You can rotate the plot like here: https://stackoverflow.com/questions/13593949/how-to-rotate-one-plot-out-of-many-when-using-knitr but using rpart.plot I don't see a chance. – jakob-r Jun 01 '18 at 14:35
  • @PhilippPro this worked. Pleas add this comment as an answer and I will accept it. – Javide Jun 03 '18 at 01:18

1 Answers1

1

Have you tried so set fig.height and fig.width, for example {r ggpair, echo=FALSE, message = FALSE, warning = FALSE, fig.height = 12, fig.width = 12}

PhilippPro
  • 659
  • 4
  • 12