There are 3 questions here:
- To change the axis labels to italics, one needs adjust the
x.axis.text, see the question/answers referenced at the bottom.
- To change the ordering of the axis labels, you need to specify the
variable Species as a factor variable defining the desire order of
the levels.
- Finally, to change the color scheme, use the
scale_fill_
function. I like the colorBrewer package with several good color schemes available. There
are few other define scale_fill options available.
Note: this a barchart and not a histogram.
See the comments for additional details:
DAta <- read.table(text="Species DNA LINE LTR SINE Helitron Unclassified Unmasked
darius 2.68 10.37 18.00 1.52 3.64 0.03 63.79
Derian 2.74 10.59 16.61 1.56 4.24 0.03 64.23
rats 2.77 10.97 15.20 1.57 4.69 0.03 64.77
Mouos 2.53 10.42 17.33 1.42 3.68 0.02 64.6", header=TRUE)
#updated method to reshape data. tidyr is replacement for reshape2
library(tidyr)
library(tidyr)
DF1 <- pivot_longer(DAta, cols=-1, names_to = "Classification", values_to = "Value" )
#Set Species as factors defining the order of the labels
DF1$Species<-factor(DF1$Species, levels=c("darius", "Derian", "rats", "Mouos"))
library(ggplot2)
ggplot(DF1, aes(x = Species, y = Value, fill = Classification)) +
geom_bar(stat = "identity") +
scale_fill_brewer(palette = "Pastel1") +
theme(axis.text.x = element_text(face="italic"))
Option: If the number of columns or the naming of the columns can change then here is a potential option for maintaining the proper ordering of the Species names:
#retrieves column names from original dataframe the 2nd to the end
# assumes the columns are "Species" and then only the species names
DF1$Species<-factor(DF1$Species, levels= names(DAta)[-1])
To adjust the axis labels here is a good reference:
Changing font size and direction of axes text in ggplot2