Как я могу показать ошибку внутри этого графика? - PullRequest
2 голосов
/ 09 февраля 2020

Это то, что я пробовал, я не знаю, какой код использовать для ошибки (всего 2 десятичных знака в каждом маленьком квадрате).

ggplot(
   grid,
   aes(x = as.factor(mtry), y = as.factor(ntree), fill = error)
   )+ 
labs(title = "Configuración de parámetros de Random Forest", x = "Número de predictores (mtry)", y= "Número de muestras bootstrap (ntree)" )+ 
geom_raster()+
scale_fill_continuous(trans = "reverse")+
theme_minimal()+
guides(fill = FALSE)

1 Ответ

1 голос
/ 09 февраля 2020

С помощью geom_text вы можете показать ошибку внутри каждого квадрата.

# A simple dataset to test the code
grid <- read.table(text="
mtry ntree error
1  1000  0.4
2  1000  0.301
3  1000  0.25
1  2000  0.35
2  2000  0.28
3  2000  0.203
", header=T)

ggplot(grid, aes(x = as.factor(mtry), y = as.factor(ntree), fill = error))+ 
  labs(title = "Configuración de parámetros de Random Forest", 
           x = "Número de predictores (mtry)", 
           y = "Número de muestras bootstrap (ntree)" ) + 
  geom_raster()+
  geom_text(aes(label=round(grid$error,2))) +
  scale_fill_continuous(trans = "reverse")+
  theme_minimal()+
  guides(fill = FALSE)

enter image description here

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...