This command puts the x axis labels at 90 degrees , how can I make it 45 degrees

boxplot(abcd$diameter~abcd$sample, las=2,cex.axis=0.5,xlab=NA

??

This command puts the x axis labels at 90 degrees , how can I make it 45 degrees

boxplot(abcd$diameter~abcd$sample, las=2,cex.axis=0.5,xlab=NA

??

Hi @ply you could get a better help if you put a reprex of you data. See this please,

```
# Example of df
set.seed(123) # Seed for reproducibility of code
abcd <- data.frame(
diameter = rnorm(100, mean = 10, sd = 2),
sample = rep(letters[1:4], each = 25))
# boxplot with x axis 45 grades.
boxplot(abcd$diameter ~ abcd$sample, las = 2, cex.axis = 0.5, xlab = NA)
```

But I think that is better use ggplot2:

```
library(ggplot2)
ggplot(abcd, aes(x = sample, y = diameter)) +
geom_boxplot() +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) + # Set axis 45 grades
labs(x = NULL)
```

1 Like

In pure base R, that doesn't seem possible; as discussed here, you can overwrite these labels with new labels with the desired angle:

```
boxplot(abcd$diameter ~ abcd$sample, xlab = NA, xaxt = 'n')
text(x = seq_along(unique(abcd$sample)),
y = par("usr")[3]-0.25,
labels = unique(abcd$sample),
xpd = TRUE,
srt = 45)
```

Briefly, `xaxt = "n"`

removes the original labels, `xpd = TRUE`

prevents clipping of the new labels. All that's left is to compute your own `x`

, `y`

and `labels`

parameters, and you can indicate the angle in `srt`

.

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.