Reputation: 121
I have this code to create a bar plot, but I want to change the names in the x axis to species names for example, and I would like to make the font smaller so that I can fit it all in. I ave tried using the cex function in various combinations, but has not worked. I would be grateful for a suggestion?
count <-
matrix(c(16,102,11,106,15,95,26,87,18,99,21,103,12,110,30,103,10,107,20,87,13,110,17,93), nrow = 2)
barplot(count, beside=T, legend =T, ylim=c(0,130),
col=c("darkolivegreen3", "firebrick1"),
ylab="Frequency (no. of moths)", las = 3,
names = c("tiger\nCo", "tiger\nCr" , "eyes\nCo", "eyes\nCr", "mottled\nCo","mottled\nCr", "pepperL\nCo","pepperL\nCr", "pepperD\nCo","pepperD\nCr", "convol\nCo", "convol\nCr"))
legend(6,130, legend=(c("survived","predated")), pch=c(15,22), cex=0.8, col=c("darkolivegreen3","firebrick1"))
Upvotes: 7
Views: 20528
Reputation: 263352
Well, according to the ?barplot
page there is a cex.names
argument:
barplot(count, beside=T, legend =T, ylim=c(0,130),
col=c("darkolivegreen3", "firebrick1"),
ylab="Frequency (no. of moths)", las = 3,
cex.names=0.8,
names.arg = c("tiger\nCo", "tiger\nCr" , "eyes\nCo", "eyes\nCr",
"mottled\nCo","mottled\nCr", "pepperL\nCo",
"pepperL\nCr", "pepperD\nCo","pepperD\nCr",
"convol\nCo", "convol\nCr"))
legend(6,130, legend=(c("survived","predated")), pch=c(15,22),
col=c("darkolivegreen3","firebrick1"))
I admit that finding the right cex.* argument is sometimes difficult and sometimes requires separate calls to axis, but here it seems nigh unto trivial.
Upvotes: 11