未选择的条目显示在轴上 - Crosstalk+Plotly 条形图
Unselected entries displayed on axis - Crosstalk+Plotly bar-chart
编辑
这似乎是 plotly 社区已知的问题
github plotly issue #689
.
上有一个类似的问题
很遗憾,似乎还没有可用的解决方案。任何建议将不胜感激。
我正在尝试使用 Crosstalk 和 Plotly 创建仪表板,但遇到了意外行为。
通过串扰过滤器进行选择时,Plotly 条形图会为未选择的条目留下“空白”。
作为一个可重现的例子,假设我想比较城市人口,我得到的是这个(代码在底部):
很可能是我遗漏了一些东西,有没有办法消除差距?关于避免该问题的类似比较的可行方法的任何建议?
提前致谢。
代码:
---
title: "Crosstalk+Plotly bargraph selection"
---
```{r setup, include=FALSE}
options(stringsAsFactors = FALSE)
library(crosstalk)
library(dplyr)
library(plotly)
#data on cities' population
city_pop <- data.frame("City" = c("Florence", "Milan", "Venice"),
"Population" = c(382258, 1352000, 261905))
#setting up Crosstalk shared data
sd <- SharedData$new(city_pop, key = city_pop$city)
#filter for the cities
filt <- filter_select(
id = "select_name",
label = "Selected City",
sharedData = sd,
group = ~City)
#barplot of cities' population
bars_pop <- plot_ly(sd, x = ~City, y = ~Population) %>%
add_bars(width=0.2,
x = ~City,
y = ~Population,
color = I("#89CFF0"),
name = "",
opacity=.9,
hoverinfo = 'y',
hovertemplate = paste('%{x} <br> number of Residents: %{y}<extra></extra>')
)
```
```{r, echo=FALSE}
filt
bars_pop
```
这对我有用 - 在它发生的轴上,设置 categoryorder = "trace"
。
例如,
plot_ly(...) %>% layout(yaxis = list(categoryorder = "trace"))
编辑
这似乎是 plotly 社区已知的问题
github plotly issue #689
很遗憾,似乎还没有可用的解决方案。任何建议将不胜感激。
我正在尝试使用 Crosstalk 和 Plotly 创建仪表板,但遇到了意外行为。 通过串扰过滤器进行选择时,Plotly 条形图会为未选择的条目留下“空白”。
作为一个可重现的例子,假设我想比较城市人口,我得到的是这个(代码在底部):
很可能是我遗漏了一些东西,有没有办法消除差距?关于避免该问题的类似比较的可行方法的任何建议?
提前致谢。
代码:
---
title: "Crosstalk+Plotly bargraph selection"
---
```{r setup, include=FALSE}
options(stringsAsFactors = FALSE)
library(crosstalk)
library(dplyr)
library(plotly)
#data on cities' population
city_pop <- data.frame("City" = c("Florence", "Milan", "Venice"),
"Population" = c(382258, 1352000, 261905))
#setting up Crosstalk shared data
sd <- SharedData$new(city_pop, key = city_pop$city)
#filter for the cities
filt <- filter_select(
id = "select_name",
label = "Selected City",
sharedData = sd,
group = ~City)
#barplot of cities' population
bars_pop <- plot_ly(sd, x = ~City, y = ~Population) %>%
add_bars(width=0.2,
x = ~City,
y = ~Population,
color = I("#89CFF0"),
name = "",
opacity=.9,
hoverinfo = 'y',
hovertemplate = paste('%{x} <br> number of Residents: %{y}<extra></extra>')
)
```
```{r, echo=FALSE}
filt
bars_pop
```
这对我有用 - 在它发生的轴上,设置 categoryorder = "trace"
。
例如,
plot_ly(...) %>% layout(yaxis = list(categoryorder = "trace"))