我想在ggvis图中消除x-axis
中未使用的因子值。
我有data.frame
choices <- c("Value1", "Value2",
"Value3", "Value4",
"Value5", "Value6",
"Value7", "Value8",
"Value9", "Value10",
"Value11", "Value12")
levele <- c("AT1","AT2","AT3","AT4","AT5","RT1","AT6","AT7","AT8","AT9","AT10","RT2")
number_value1 <- sample(1:100,22)
number_value2 <- sample(1:100,22)
df1 <- data.frame(product = c(rep("Product1",12),rep("Product2",10)), name = c(choices,choices[1:10]),
short_name = c(levele,levele[1:10]),number = number_value1, number2 = number_value2)
当我想创建一个仅基于Product2
的数据的ggvis时,我得到了
df1 %>%
dplyr::filter(product == "Product2") %>%
ggvis(x = ~short_name,y = ~number) %>%
layer_points(size := 120,fill = ~short_name)
图表还显示未使用的因子值。我不想看到这一点,所以我使用x = ~factor(short_name)
来消除这些未使用的案例。
df1 %>%
dplyr::filter(product == "Product2") %>%
ggvis(x = ~short_name,y = ~number) %>%
layer_points(size := 120,fill = ~short_name)
=============================================== =====================
所以没关系。问题是当我想在Shiny app中做同样的事情时,它有可能操纵轴。有2个dataframes
,其中有2个Products
,name
的数量不同。当我在Product1
部分中将Produt2
更改为Select Product
时,我会在x轴中包含所有因素,也会使用未使用的因子。我的代码是here。如果有人知道如何正确实现它?