I have a plot whose legend I want to appear at the bottom and in two
rows, however, guide_legend(nrow=2) appears not to be working. What am
I doing wrong in my code?
Incidentally, I came across this post [1] but no solution was provided.
### Code ###
require(ggplot2)
require(reshape2)
require(grid)
require(scales)
library(gridExtra)
p3dataset <- read.csv(text="Aspect,Feature,Scale,Count
X,A,Legend #1,4
X,A,Legend #2,12
X,A,Legend #3,7
X,A,Legend #4,3
X,A,Legend #5,0
Y,A,Legend #1,2
Y,A,Legend #2,16
Y,A,Legend #3,3
Y,A,Legend #4,5
Y,A,Legend #5,0
X,B,Legend #1,2
X,B,Legend #2,10
X,B,Legend #3,8
X,B,Legend #4,6
X,B,Legend #5,0
Y,B,Legend #1,5
Y,B,Legend #2,11
Y,B,Legend #3,7
Y,B,Legend #4,3
Y,B,Legend #5,0
"
)
# p3 --plot #3
# S& U
##p3dataset <- read.table("ggplot2-legend-rows.dat", header=TRUE, sep=",")
p3experimentdataset <- p3dataset
ggplot(p3experimentdataset, aes(x=Feature, y=Count, fill=Scale,
width=0.75)) + geom_bar(stat="identity") + labs(x="", y="") +
facet_wrap(~ Aspect,ncol=1) + theme(legend.title=element_blank(),
legend.position="bottom", axis.text.x=element_blank(),
axis.ticks.x=element_blank(), axis.ticks.y=element_blank()) +
scale_fill_brewer(palette="Dark2") + ggtitle("The Plot in Question") +
coord_flip() + guides(col = guide_legend(nrow = 2))
[1]
https://groups.google.com/d/topic/ggplot2/lHVelyk2DCg/discussion
Lighton Phiri
http://lightonphiri.org