Strange small bars in a mosaic plot

by Henk Straten   Last Updated December 29, 2017 18:26 PM

I have the following dataset:

Category <- c("Bankpass", "Bankpass", "Bankpass", "Moving", "Moving")
Subcategory <- c("Stolen", "Lost", "Login", "Address", "New contract")
Weight <- c(10,20,13,40,20)
Duration <- as.character(c(0.2,0.4,0.5,0.44,0.66))
df <- data.frame(Category, Subcategory, Weight, Duration)

I use that to create the following plot:

#install.packages("ggmosaic")
ggplot(data = df) +
 geom_mosaic(aes(weight = Weight, x = product(Category), fill=Duration), 
 na.rm=TRUE) +    theme(axis.text.x=element_text(angle=-25, hjust= .1))

This works however, I see small slices in the bar that dont make sense.

enter image description here

Any thoughts on how I can get rid of them?

Tags : r ggplot2


Answers 1


inside geom_mosaicadd offset = 0.

ggplot(data = df) +
 geom_mosaic(aes(weight = Weight, x = product(Category), fill=Duration), 
 offset = 0, na.rm=TRUE) +  
 theme(axis.text.x=element_text(angle=-25, hjust= .1))

enter image description here

esm
esm
December 29, 2017 18:25 PM

Related Questions


R - How to find points within specific Contour

Updated May 28, 2015 23:11 PM

How to see the code of a stored plot (ggplot)

Updated May 29, 2015 01:11 AM

R ggplot remove certain items from legend

Updated April 03, 2015 23:11 PM

add second axis label

Updated April 10, 2015 23:11 PM

Error in facet_grid in ggplot2

Updated October 09, 2016 09:11 AM