Rabik R
Rabik R

Reputation: 33

Display axis labels below mosaicplot

I'm trying to change the default settings on displaying the x values at the top of the plot to the bottom of the plot.

Here is a small example:

Betta <- c(1,12,23,20)
dim(Betta) <- c(2,2) 
dimnames(Betta) <- list(Temperature = c("28", "25"), Flare = c("Yes", "No"))
mosaicplot(x = Betta, main = "Title")

enter image description here

To make things clear, I'm trying to move the temperature values 28 and 25 to the bottom on the graph, right above x axis "Temperature".

Appreciate the help!

Upvotes: 3

Views: 1472

Answers (1)

Mamoun Benghezal
Mamoun Benghezal

Reputation: 5314

You can use package ggmosaic with the example below

df <- as.data.frame(as.table(Betta)) # first, transform the contingency table into a data.frame
library(ggmosaic)
ggplot(data=df)+
    geom_mosaic(aes(weight=Freq,x=product(Temperature), fill=Flare))+
     labs(x="Temperature")

enter image description here

Upvotes: 2

Related Questions