繁体   English   中英

如何根据 Shiny App 中 geom_polygon 中的“数字”列进行填充

[英]How to fill based on a "numeric" column in geom_polygon in Shiny App

我有这个以下Slider

sliderInput(
        inputId = "year",  #  variable name that is used in server.R input$var_name
        label = "Year Selector",  # Title tha appears above the slider
        min = 2005, max = 2020, # min and max on the slider
        value = 2007 # initial variable value
      )

以及具有显示地图的绘图命令的服务器代码

birth_map_data <- reactive({
      full_join(vn_spatial_region, birthDataByRegion[c("Region/Year", as.character(input$year))], by = c("sub_region_en" = "Region/Year"))
    })
    
    vietnam_birth_map_data <- reactive({
      full_join(vietnam_prov_df, birth_map_data(), by = c("prov_names" = "Name"))
    })


    output$distPlot <- renderPlot({
      ggplot() +
      geom_sf(data = vn_spatial_region) +
      geom_polygon(data=vietnam_birth_map_data(), aes(fill = `as.character(input$year)`, x = long, y = lat, group = group), color = "grey80")
    })

aes 中的fill参数基于相应的年份,因此例如在 2005 年,它将是 fill = /``2005``/ (反引号)。 但是,在反应式上下文中,我找不到对象“as.character(input$year)”(在反引号中)。

我将如何解决这个问题?

你有没有尝试过:

output$distPlot <- renderPlot({
      ggplot() +
      geom_sf(data = vn_spatial_region) +
      geom_polygon(data=vietnam_birth_map_data(), aes(fill = input$year, x = long, y = lat, group = group), color = "grey80")
    })

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM