gpt4 book ai didi

r - 调整条形图中的图例位置

转载 作者:行者123 更新时间:2023-12-01 12:50:19 26 4
gpt4 key购买 nike

我需要在图外某处的适当位置调整以下条形图的图例

COLORS=rainbow(18)
barplot(sort(task3_result$respondents_share,decreasing = TRUE), main="Share of respondents that mentioned brand among top 3 choices ", names.arg=task3_result$brand, col = COLORS)
legend("right", tolower(as.character(task3_result$brand)), yjust=1,col = COLORS, lty=c(1,1) )

enter image description here

最佳答案

谢谢大家,我无法解决问题,但我使用 ggplot 达到了我的目标,

windows(width = 500, height= 700)
ggplot(data = task3_result, aes(x = factor(brand), y = respondents_share, fill = brand)) +
geom_bar(colour = 'black', stat = 'identity') + scale_fill_discrete(name = 'brands') + coord_flip()+
ggtitle('Share of respondents that mentioned brand among top 3 choices') +xlab("Brands") + ylab("Share of respondents")

enter image description here

关于r - 调整条形图中的图例位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34387005/

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