Keno
Keno

Reputation: 143

Changing the font size of x-axis labels in forestplot R function

I am generating a forest plot in R using the following code:

forestplot(livertabletext, 
            liverdata,new_page = TRUE,
            is.summary=c(TRUE,rep(FALSE,3),TRUE),
            clip=c(0.1,2.0), 
            xlog=TRUE, 
            graph.pos=3,
            boxsize=0.1,
            xticks=c(0.2,0.5,1,2,5,7),
            txt_gp = fpTxtGp(cex=0.75),
            col=fpColors(box="royalblue",line="darkblue", summary="royalblue"))

The fpTxtGp(cex=0.75) parameter only changes the font size of the other elements of the graph, not the x-axis. I tried using a smaller font size so that relatively, it is closer to the default x-axis font size, but that made the x-axis font even smaller.

I've searched for a while now in the documentation with no luck.

Upvotes: 3

Views: 9562

Answers (2)

Bruno Ar.
Bruno Ar.

Reputation: 21

Try using: axes = gpar(cex = 0.6)

forestplot(livertabletext, 
        liverdata,new_page = TRUE,
        is.summary=c(TRUE,rep(FALSE,3),TRUE),
        clip=c(0.1,2.0), 
        xlog=TRUE, 
        graph.pos=3,
        boxsize=0.1,
        xticks=c(0.2,0.5,1,2,5,7),
        txt_gp = fpTxtGp(cex=0.75),
        axes = gpar(cex = 0.6),
        col=fpColors(box="royalblue",line="darkblue",    summary="royalblue"))

Upvotes: 2

Sokolokki
Sokolokki

Reputation: 863

You can separately change the font size of elements by setting txt_gp = fpTxtGp(ticks=gpar(cex=4)). The available options are: label, summary, xlab, title, ticks and legend.

Here is an example of increasing the font size of X axis ticks:

ask <- par(ask=TRUE)

row_names <- list(list("test = 1", expression(test >= 2)))
test_data <- data.frame(coef=c(1.59, 1.24),
                    low=c(1.4, 0.78),
                    high=c(1.8, 1.55))
forestplot(row_names,
       test_data$coef,
       test_data$low,
       test_data$high,
       txt_gp = fpTxtGp(ticks=gpar(cex=4)),
       xlab = "X axis")

Upvotes: 4

Related Questions