首页 > 解决方案 > Partially suppress labels in R

问题描述

I am working with the R programming language. I am trying to plot "Decision Trees" using the "rpart.plot" library as shown below:

#load libraries
    library(rpart)
    library(rpart.plot)

#load data
    data(iris)

#fit rpart model (i.e. decision tree)
    r = rpart(Species ~., data=iris)

#plot model
    rpart.plot(r)

enter image description here

I have noticed that sometimes the labels in this picture will say "iris$Petal.Length" and sometimes they will just say "Petal.Length".

Question: Is there a way to "suppress" these labels and always show the labels without the name of the dataset and the "$" symbol? I.e. Is it always possible to show the labels as only "Petal.Length" ? (So that they always look like the image I have posted)

Thanks

标签: rdata-visualization

解决方案


you may define the model like this:

r = rpart(iris$Species ~iris$Petal.Length)

in this case, you'll see the dataset name in the labels

always try to use your dataset in the rpart() function like this:

r = rpart(Species ~., data=iris)

推荐阅读