在一个闪亮的应用程序中,ggmosaic给出了一个错误:将离散值提供给连续刻度

时间:2019-02-18 14:31:58

标签: r ggplot2 shiny ggmosaic

在闪亮的应用程序中,将进行绘图。其中之一,基于ggmosaic和ggplot2,我无法渲染。它给我一个错误: “警告:错误:将离散值提供给连续刻度”

尝试在控制台上重现它,当未加载ggmosaic时(库(ggmosaic)),我收到相同的错误。

# Restart R
library(ggplot2)
library(dplyr)
#library(ggmosaic) not loaded

test_mosaic <- tibble::tribble(
    ~source, ~RegionSplit, ~RegionReport, ~SuppliesSplit, ~SuppliesPlot, ~fYear,  ~measure,
  "Transac",    "Region1",     "Region1",    "Supplies1",     "MarketA",  2017L,  77010005,
  "Transac",    "Region1",     "Region1",    "Supplies2",     "MarketA",  2017L,  10880005,
  "Transac",    "Region1",     "Region1",    "Supplies3",     "MarketA",  2017L,    520005,
    "Store",    "Region1",     "Region1",    "Supplies1",     "MarketA",  2017L,    210005,
    "Store",    "Region1",     "Region1",    "Supplies2",     "MarketA",  2017L,     33305
  )

test_mosaic <- 
  test_mosaic %>% 
  dplyr::mutate_if(is.character, forcats::as_factor) %>% 
  dplyr::mutate_if(is.integer, ~forcats::as_factor(as.character(.)))

ggplot2::ggplot(data = test_mosaic) + 
  ggmosaic::geom_mosaic(
    ggplot2::aes(weight = as.numeric(measure), 
                 x = ggmosaic::product(source, SuppliesSplit), 
                 fill = source),
  na.rm = TRUE, offset = 0.005)

# Error: Discrete value supplied to continuous scale

如果已加载ggmosaic,则一切正常。在我闪亮的应用程序中,我必须具有

可用的ggmosaic函数
#' @importFrom ggplot2 ggplot aes
#' @importFrom ggmosaic geom_mosaic product

有几个ggplot2绘图工作正常,所以在这种情况下,我真的不明白什么是行不通的。我错过了明显的东西吗?

谢谢。

0 个答案:

没有答案