0

如何修改通过将 ggplot 应用于使用 ranger 算法构建的插入符号对象生成的默认绘图图例?例如,假设我希望图例标题为“Splitting algo”而不是默认的“Splitting Rule”。

library(caret)

trainIndex <- createDataPartition(iris$Species, p = 0.80, list = FALSE)

train <- iris[ trainIndex,]

test  <- iris[-trainIndex,]

rfs <- train(Species ~ ., data = train, trControl = trainControl(method = "cv", number = 10), method = "ranger", tuneGrid = expand.grid(mtry = seq(1, 3, 1), splitrule = c("gini", "extratrees"), min.node.size = 1))

ggplot(rfs) + 
  xlab("Number of parameters") +
  ylab("Accuracy") +
  theme(legend.title = "Splitting algo")
4

1 回答 1

1

您使用和设置name图例。scale_color_discretescale_shape_discrete

library(ggplot2)

ggplot(rfs) + 
  xlab("Number of parameters") +
  ylab("Accuracy") +
  scale_color_discrete(name = "Splitting algo")  +
  scale_shape_discrete(name = "Splitting algo")

在此处输入图像描述

于 2021-02-04T04:00:04.557 回答