【问题标题】:How can I show the error inside this graph?如何在此图中显示错误?
【发布时间】:2020-02-09 12:18:23
【问题描述】:

这是我尝试过的,我不知道要使用什么代码来解决错误(每个小方块内只显示 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)

【问题讨论】:

    标签: r ggplot2 graph numbers


    【解决方案1】:

    使用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)
    

    【讨论】:

      猜你喜欢
      • 2022-07-12
      • 1970-01-01
      • 2021-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多