Boxplot Axis and Text

HELP! I'm new to Rstudio.
How can change the orientation of my x-axis to be perpendicular to the axis? and how do I make the names in the x-axis to be in Italics?

Code:
#boxplot of the species’ growth rates

boxplot((Spines$GR ~ Spines$Sp),
xlab= "Species",
ylab= "Growth rate (cm/year)",
main = "Growth Rates of Different Species",
names=c("Pinus sylvestris","Pinus uncinata","Pinus pinea","Pinus halepensis","Pinus nigra"),
col = c("grey","grey","grey","grey","grey"))

Hi, and welcome!

Like R itself, many of us who answer questions here follow the principle of lazy evaluation. That why you should see the FAQ: What's a reproducible example (`reprex`) and how do I create one? The most common problem, even when complete code such as you've provided, is a lack of the data object.

There's a variety of ways to handle this:

  1. dput(your_data) and cut and paste the output
  2. If large, do the same with a sample
  3. gist a csv file
  4. Find a built-in data set that has the same structure

In this case, the iris dataset is parallel.

I'm going to be further lazy and use ggplot2 because it makes the solution easier.

suppressPackageStartupMessages(library(dplyr)) 
suppressPackageStartupMessages(library(ggplot2))

box <- ggplot(data=iris, aes(x=Species, y=Sepal.Length))
box + geom_boxplot(aes(fill=Species)) + 
  ylab("Sepal Length") + ggtitle("Iris Boxplot") +
  stat_summary(fun.y=mean, geom="point", shape=5, size=4) +
  coord_flip()

Created on 2020-02-11 by the reprex package (v0.3.0)

This is the dataset.
I hope this works

Spines <- read.table("Spanish_pines.txt",header=TRUE)

#boxplot of the species’ growth rates

boxplot((Spines$GR ~ Spines$Sp),
xlab= "Species",
ylab= "Growth rate (cm/year)",
main = "Growth Rates of Different Species",
names=c("Pinus sylvestris","Pinus uncinata","Pinus pinea","Pinus halepensis","Pinus nigra"),
col = c("grey","grey","grey","grey","grey"))

The dataset can be copied and pasted onto R

Great! I inadvertently replied before finishing. See if you can adapt the example, and if not, we'll switch to your data for debugging.

What i meant to say previously, I'm trying to change the orientation of the named species on the x-axis to be perpendicular and also change the font of names to be in Italics?
An example of this online:
https://www.researchgate.net/figure/Box-plots-of-daily-growth-rates-representing-various-species-in-the-Colletotrichum_fig1_236741416

My boxplot looks like this:

Well! I sure didn't cover myself with glory carefully reading the question!

suppressPackageStartupMessages(library(dplyr)) 
suppressPackageStartupMessages(library(ggplot2))
suppressPackageStartupMessages(library(ggthemes)) 

box <- ggplot(data=iris, aes(x=Species, y=Sepal.Length))
box + geom_boxplot(aes(fill=Species)) + 
  ylab("Sepal Length") + ggtitle("Iris Boxplot") +
  stat_summary(fun.y=mean, geom="point", shape=5, size=4) +
  theme(axis.text.x = element_text(angle = 90, face = "italic")) 

Created on 2020-02-11 by the reprex package (v0.3.0)

(corrected by removing theme_tufte() (to get a white background)

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