gpt4 book ai didi

r - 使用 opts() 更改图例位置/方向无效

转载 作者:行者123 更新时间:2023-12-03 23:28:57 25 4
gpt4 key购买 nike

创建以下绘图会导致图例垂直放置在右侧,而不是水平放置在底部,如对 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()

enter image description here

如何在正确的位置获得图例?

最佳答案

问题是 theme_bw()在调用 opts() 之后放置,并重置一些默认值。只需放置theme_bw()之前 opts() :

ggplot(data = dat, aes(x = x, y = y, colour = grp)) + 
geom_point() +
theme_bw() +
opts(legend.position = "bottom", legend.direction = "horizontal")

备注 : 从版本 0.9.2 opts已经 replaced通过 theme :
theme(legend.position = "bottom", legend.direction = "horizontal")

enter image description here

关于r - 使用 opts() 更改图例位置/方向无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7128573/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com