小编Ray*_*Ray的帖子

如何从 xaxis 中删除空因子

尝试使用 filter_select() 和无光泽的工作制作交互式绘图条形图。我正在处理许多机场(> 100)的数据。条形图通常过于拥挤,无法支持用户将在一个机场 (APT_x) 上观察到的性能(值 VAL)与同级的子集进行比较。这个想法是使用过滤器让用户选择机场的子集。

# create a dummy table with data for year, airport, and oberved value
yr <- c(2017, 2018, 2019)
ap <- c("APT_1", "APT_2", "APT_3", "APT_N")

df <- expand.grid(YEAR = yr, APT = ap)
df$VAL <- c(10, 11, 12, 14, 9, 8, 7, 6, 2, 10, 12, 13)

library(plotly)
# shared data
df_sh <- highlight_key(df, key=~APT)

# filters
ap_filter <- filter_select(id="airport",label="filter airport", sharedData=df_sh, group=~APT)

# stacked bar chart
bc <- df_sh %>% plot_ly(x=~APT, y=~VAL, color=~factor(YEAR)) …
Run Code Online (Sandbox Code Playgroud)

r filter plotly

5
推荐指数
1
解决办法
268
查看次数

标签 统计

filter ×1

plotly ×1

r ×1