如何在Plotly / Shiny中设置渐变色标

时间:2019-03-11 16:17:39

标签: r shiny plotly

我正在尝试在闪亮的应用程序中创建一个交互式的绘图选项卡,以显示每个潮汐高度不同的栖息地的点数百分比。问题是,每当用户选择其他标签时,百分比的色标就会改变。有没有办法保持一致?

我的身材代码在这里:

output$tide = renderPlotly({
habitat_tides %>%
  filter(veg_class != "Natural Pond (non-vegetated)") %>% 
  filter(veg_class != "Sparsely Vegetated Talus") %>% 
  filter(tag == input$tag) %>% 
  mutate(tide = factor(tide, levels = c("L", "M", "H"))) %>%
  group_by(tag) %>% 
  count(veg_class, tide) %>%
  mutate(total = sum(n),
         pcnt = n / total *100) %>%
  ggplot(height = 500) +
  geom_point(aes(veg_class, tide, size = pcnt, color = pcnt)) +
  theme_bw() +
  theme(axis.text.x = element_text(angle = 45, vjust = 0.5),
        text = element_text(size=10)) +
  scale_color_gradientn(name = "Percent",
                      colors = brewer.pal(4, "Blues")) +
  labs(title = input$tag, x = "Habitat Type", y = "Tide Height") 
  })

0 个答案:

没有答案