learner
learner

Reputation: 2742

R boxplot long names out of the plot area

My boxplot names are long and making it vertical chop these names. How can I avoid the names/labels of boxplot going out of the plot area?

dat <- data.frame(values = rnorm(100), group = gl(2, 50))
levels(dat$group) <- c("reallyreallylonglabel", 
                       "anevenlooooooooooooongerlabel")
boxplot(values ~ group, data = dat,  las = 3)

Upvotes: 0

Views: 1473

Answers (2)

Rorschach
Rorschach

Reputation: 32426

If you use the ggplot library the labels should come out nicely. library(ggplot2)

dat <- data.frame(values = rnorm(100), group = gl(2, 50))
levels(dat$group) <- c("reallyreallylonglabel", 
                       "anevenlooooooooooooongerlabel")


ggplot(dat, aes(factor(group),values)) + stat_boxplot()

Upvotes: 1

Jean V. Adams
Jean V. Adams

Reputation: 4784

Increase the bottom margin using the par() function.

par(mar=c(14, 3, 1, 1))
boxplot(values ~ group, data=dat, las=3)

Upvotes: 3

Related Questions