An R package to create mosaic plots in the 'ggplot2' framework.
Questions tagged [ggmosaic]
22 questions
9
votes
3 answers
Adding counts to ggmosaic, can this be done simpler?
I would like to make a mosaic plot using the ggmosaic package and add the counts as shown in the example below.
The example sort of works, but I find the structure of the code quite ugly.
Do you have any suggestions on how I can improve the code,…

midtiby
- 14,550
- 6
- 34
- 43
5
votes
2 answers
Add text labels to a ggplot2 mosaic plot
Using the following data:
Category <- c("Bankpass", "Bankpass", "Bankpass", "Moving", "Moving")
Subcategory <- c("Stolen", "Lost", "Login", "Address", "New contract")
Weight <- c(10,20,13,40,20)
Duration <-…

Henk Straten
- 1,365
- 18
- 39
4
votes
2 answers
geom_mosaic: X axis tick labels not showing?
I'm using ggmosaic::geom_mosaic to generate a mosaic plot. I can't seem to get the value labels for my independent variable to show on the X axis. The variable is a labelled factor, with levels labelled "1", "2", "3". I'm sure it's something stupid…

West_End_Line
- 179
- 6
3
votes
1 answer
In R language package `ggmosaic`, how to add weight percent label to the columns
In package ggmosaic, how to add weight percent label to the columns ? I want to add the percent value of each column (every column totla percent equalt 100%). Thanks!
library(tidyverse)
library(ggmosaic)
ggplot(data = titanic) +
…

anderwyang
- 1,801
- 4
- 18
2
votes
1 answer
Problems with quasiquotation inside ggplot custom function using ggmosaic::product
I want to create a function that taking a data base, variable_1 y variable_2 builds a mosaic plot!
var_1<-rep(c("A","B","C","B","A","C"),10)
var_2<-c(rep(c("1","0"),10),rep("0",5),rep(c("0","1","0"),10),rep("1",5) )
dat<-data.frame(var_1,var_2)
The…

Francisco
- 119
- 6
1
vote
1 answer
Creating mosaicplot with different colors in each field
I want to create a mosicplot (2x2), where the counterpart have the same color.
So the mosaicplot should have a colorpalette like:
Here is the structure of the data i used for the graphic:
data <- data.frame(G1 = c("A", "B", "B", "A", "B", "B", "B",…

francis
- 11
- 2
1
vote
0 answers
How to make a percent stacked barplot of interactions with ggplot?
Let's say our data frame is mtcars[, c("vs", "am")]. I want a percent stacked barplot/barchart with 2 columns, one for vs and other for am, each one with 2 groups, ==1 and ==0, but splitted in such a way that looking at the 2 columns I would observe…

iago
- 2,990
- 4
- 21
- 27
1
vote
2 answers
product() in geom_mosaic() not accepting reactive inputs on R Shiny?
I'm playing around with the geom_mosaic() function (part of the ggmosaic package) on R Shiny and came up with a problem I've been trying to solve for a few days.
First, some sample data:
a <- "a"
b <- "b"
c <- "c"
df <- tribble(
~id, ~var1,…

Felix T.
- 520
- 3
- 11
1
vote
1 answer
How can I flip a mosaic plot in ggmosaic?
How can I flip a mosaic plot in ggmosaic? For example, I want this:
to look like this:
Note "present" is on the top in the first plot and on the bottom in the second graph. I would like to make "present" on the bottom in the first plot.
The data…

wisamb
- 470
- 3
- 11
1
vote
0 answers
Modify x axis label for each facet
I have this mosaic plot
I'd like to have only label on x-axis for individuals in correct facet.
for example you can see that in the last facet there are only 7 bars. i'd like to show only x axis labels for those 7 bars.
Hope i have been clear…

Marco Fumagalli
- 2,307
- 3
- 23
- 41
0
votes
2 answers
Modify the colors in geom_mosaic() plot
I want to plot a mosaic plot with ggplot2 and choose the colors manually, i.e, pick the colors for each category (A, B, C, D, E, F) on the y axis. Currently, I can only select the colors for each category on the x axis (X, Y, Z) with the…

Bileobio
- 121
- 8
0
votes
0 answers
How to add percentage labels to mosaic chart with geom_mosaic?
I'm struggling to create labels for percentages in my. mosaic plot using geom_mosaic chart.
Here's my code. I got it to work for counts, but don't know how to transform it so the labels are %.
p <- ggplot(df) +
geom_mosaic(aes(x = product(gender,…

Still learning
- 1
- 1
0
votes
1 answer
How to make mosaic plot in ggplot2
I want to make mosaic plot in ggplot2,by geom_mosaic
I want to make mosaic plot, in ggplot2. that will be as same as this.
library(faraway)
(ct <- xtabs(y ~ right + left, eyegrade))
mosaicplot(ct, color = c("lightblue"),xlab="Right eye",ylab="Left…

user20606451
- 11
0
votes
1 answer
ggplot ggmosic geom_mosaic text for x axis with nested
I need to change the axis breaks in geom_mosaic.
Here is my example:
my_tibble <-
tibble(a=rep(c("a1","a2"),each=4),
b=rep(rep(c("b1","b2"),each=2),times=2),
c=rep(c("c1","c2"),times=4),
x=seq_along(b)
)
my_tibble |>
…

Erich Neuwirth
- 943
- 7
- 13
0
votes
0 answers
ggmosaic: "Discrete value supplied to continuous scale" error when ggplot2/ggmosaic is imported
In my package, I like to create a mosaic plot. In the interactive session, this works well. However, if I call the function from an fresh R session with devtools::load_all, the error "Discrete value supplied to continuous scale" is raised.
Here is a…

Karsten W.
- 17,826
- 11
- 69
- 103