Creating the following plot results in the legend being placed vertically, on the right, rather than on the bottom horizontally as indicated in the call to opts()
:
dat <- data.frame(x = runif(10), y = runif(10),
grp = rep(letters[1:2],each = 5))
ggplot(data = dat, aes(x = x, y = y, colour = grp)) +
geom_point() +
opts(legend.position = "bottom", legend.direction = "horizontal") +
theme_bw()
How do I get the legend in the correct spot?
The problem is that that theme_bw()
is placed after the call to opts()
, and resets some defaults. Just place theme_bw()
before opts()
:
ggplot(data = dat, aes(x = x, y = y, colour = grp)) +
geom_point() +
theme_bw() +
opts(legend.position = "bottom", legend.direction = "horizontal")
Note: Since version 0.9.2 opts
has been replaced by theme
:
theme(legend.position = "bottom", legend.direction = "horizontal")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With