Running ggmosaic with ggplot2

Hi,

I am trying to run a simple example of a mosaic plot using ggplot2 and ggmosaic (0.1.2).

I am getting the error

Error in is.finite(x) : default method not implemented for type 'list'

I have seen other people have this error based in the github comments here and here. I have tried the suggestions outlined without much success. Its probably something small in my settings. Has anyone come across this before

library(tidyverse)
#> Warning: package 'ggplot2' was built under R version 3.5.1
#> Warning: package 'dplyr' was built under R version 3.5.1
library(ggmosaic)
#> Warning: package 'ggmosaic' was built under R version 3.5.1
#> Loading required package: productplots
#> Warning: package 'productplots' was built under R version 3.5.1
#> 
#> Attaching package: 'ggmosaic'
#> The following objects are masked from 'package:productplots':
#> 
#>     ddecker, hspine, mosaic, prodcalc, spine, vspine
library(NHANES)
#> Warning: package 'NHANES' was built under R version 3.5.1

packageVersion("ggplot2")
#> [1] '3.0.0'

# First Test from https://github.com/tidyverse/ggplot2/issues/2746
ggplot(data = NHANES) +
  geom_mosaic(aes(weight = Weight, x = product(SleepHrsNight), fill=factor(SleepHrsNight)), na.rm=TRUE)
#> Error in is.finite(x): default method not implemented for type 'list'

# Second test from the vignette
example(geom_mosaic)
#> 
#> gm_msc> data(Titanic)
#> 
#> gm_msc> titanic <- as.data.frame(Titanic)
#> 
#> gm_msc> titanic$Survived <- factor(titanic$Survived, levels=c("Yes", "No"))
#> 
#> gm_msc> ggplot(data=titanic) +
#> gm_msc+   geom_mosaic(aes(weight=Freq, x=product(Class), fill=Survived))
#> Error in is.finite(x): default method not implemented for type 'list'

Did you try to install the dev version of ggmosaic ? It seems it has been fixed per the discussion.
And on my settings, it works. I just installed with devtools::install_github("haleyjeppson/ggmosaic")

library(tidyverse)
library(ggmosaic) # with dev version
#> Le chargement a nécessité le package : productplots
#> 
#> Attachement du package : 'ggmosaic'
#> The following objects are masked from 'package:productplots':
#> 
#>     ddecker, hspine, mosaic, prodcalc, spine, vspine
library(NHANES)

packageVersion("ggplot2")
#> [1] '3.0.0'

# First Test from https://github.com/tidyverse/ggplot2/issues/2746
ggplot(data = NHANES) +
  geom_mosaic(aes(weight = Weight, x = product(SleepHrsNight), fill=factor(SleepHrsNight)), na.rm=TRUE)

Created on 2018-09-04 by the reprex package (v0.2.0).

3 Likes

Thank you very much @cderv, this indeed fixed my problem

Glad it helped!

If your question's been answered, would you mind choosing a solution? It helps other people see which questions still need help, or find solutions if they have similar problems. Here’s how to do it: