Questions tagged [mosaic-plot]

Mosaic plots and image-plots use color and area in a 2-d discrete matrix to display "three way" categorical relationships.

76 questions
5
votes
3 answers

Is it possible to edit the axes labels for a mosaic plot from the vcd package?

data("HairEyeColor") mosaic(HairEyeColor, shade = TRUE) Are there arguments I can use to change the labels on the margins of the resulting plot above? For instance, I'd like to change "Male" to "M", "Female" to "F", to avoid text encroachment, and…
Phil
  • 7,287
  • 3
  • 36
  • 66
5
votes
1 answer

Statsmodels mosaic plot ValueError: cannot convert float NaN to integer

I have a simple pandas DataFrame, for which I would like to create a mosaic plot. Here is my code: import pandas as pd from statsmodels.graphics.mosaicplot import mosaic mydata = pd.DataFrame({'id2': {64: 'Angelica', …
DanDy
  • 451
  • 5
  • 10
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…
4
votes
1 answer

stacked geom_bar(): keep equal gaps between bars with variable widths

My sample data and plot: library(data.table) library(ggplot2) dt2 <- fread(' risk group counts low A 178 High A 1 low B 4 High B 100 low C 45 High C 83 low D 50 High D 2 ') # ggplot(dt2,…
Vasily A
  • 8,256
  • 10
  • 42
  • 76
4
votes
2 answers

R vcd::mosaic overlapping labels

I'm generating a mosaic plot with vcd::mosaic. But the text of the factors I was given are very long (cutting them is not an option, and with so many instances, introducing \n seems daunting), so there's an overlap in the texts, and I haven't been…
PavoDive
  • 6,322
  • 2
  • 29
  • 55
4
votes
1 answer

Add a numeric axis to a mosaicplot

I am plotting data using a mosaic plot (with mosaicplot()) and am considering adding a numeric axis to one dimension to clarify the size of the different groups. But, I do not understand how the plot cells are aligned to the axis since it seems to…
Thomas
  • 43,637
  • 12
  • 109
  • 140
4
votes
2 answers

mosaic()-function of the vcd package: error in adding text in the cells

I have created a mosaic plot using mosaic function in the vcd package. Now I wish to add some annotations using labeling_cells. Unfortunately, I get an error. The problem might be that it is not the standard Titanic example... library("grid");…
Karl A
  • 165
  • 11
3
votes
1 answer

Add labels to a mosaic plot in R

I have the following table x which looks like this: > x <- table(married_working_women$fem_ed, married_working_women$hom_ed) > rownames(x) <- c("< HS", "HS", "> HS") > colnames(x) <- c("< HS", "HS", "> HS") > x < HS HS > HS < HS…
Saïd Maanan
  • 511
  • 4
  • 14
3
votes
1 answer

Creating a mosaic plot with percentages

Following is the sample dataset that I have: df <- structure(list(Class = c("A", "B", "C", "D"), `Attempted` = c(374, 820, 31, 108), `Missed` = c(291, 311, 5, 15), `Cancelled` = c(330, 206, 6, 5), `Unknown` = c(950, 341, 6, 13)), class =…
amty
  • 113
  • 1
  • 10
3
votes
1 answer

Using grid to modify vcd::mosaic plots

I want to use grid to modify mosaic plots that I create with the vcd package. Specifically, I want to add precisely positioned line segments. Here is a minimal example: library(vcd) myDF <- expand.grid(fac1 = c('a', 'b', 'c', 'a'), fac2 = c('y',…
user697473
  • 2,165
  • 1
  • 20
  • 47
2
votes
1 answer

How to Plot Multiple Categorical Variables From a Google Form Survey Checkbox Grid Question and Best Visualize It in R?

very new to R and am struggling to understand how to plot multiple categorical variables. From a survey there was a question that was formatted in a checkbox grid, therefore respondents were able to check multiple options for multiple items. It…
ilc17
  • 29
  • 3
2
votes
1 answer

Add (or override) fill aesthetic to a ggplot2 autoplot function

I would like to add a fill aesthetic to an autoplot function. Specifically, to the autoplot.conf_mat function from the yardstick package. library(tidyverse) library(tidymodels) data("hpc_cv") cm <- hpc_cv %>% filter(Resample == "Fold01") %>% …
JasonAizkalns
  • 20,243
  • 8
  • 57
  • 116
2
votes
2 answers

How to plot a mosaicplot for a 1x1 contingency table?

Plotting a 1-by-1 contingency table returns an error: dat <- read.table(textConnection(' foo bar TRUE TRUE TRUE TRUE '), header = TRUE, colClasses=c('logical', 'logical')) mosaicplot(table(dat)) Error in rep.int(0, ydim) : invalid 'times' value As…
user12635841
2
votes
1 answer

The captions of my graph are overlapping. How can I fix this?

So I was plotting this code, but the text is overlapping. How can I fix this? mayors <- read.csv("https://raw.githubusercontent.com/umbertomig/intro-prob-stat-FGV/master/datasets/brmayors.csv") head(mayors) mosaicplot(table(mayors$SIGLA_PARTIDO,…
hello
  • 23
  • 2
2
votes
1 answer

Choosing Another Color Palette for a Mosaic Plot

I have this mosaic: from statsmodels.graphics.mosaicplot import mosaic mosaic_data = pd.DataFrame({'gender': labeled_gender, 'y': labeled_y}) mosaic(mosaic_data, ['gender','y'], title='Mosaic of Heart Disease Vs. Gender', ax=ax, properties={}) I…
G. M.
  • 33
  • 3
1
2 3 4 5 6