开发者

Changing legend position/direction using opts() has no effect

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()

Changing legend position/direction using opts() has no effect

How do I get the l开发者_运维技巧egend 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")

Changing legend position/direction using opts() has no effect

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜