我想让 r 条形图的图例框水平,但 ncol 不起作用
Posted
技术标签:
【中文标题】我想让 r 条形图的图例框水平,但 ncol 不起作用【英文标题】:I want to make the legend box horizontal for r bar plot but ncol is not working 【发布时间】:2021-07-18 05:53:58 【问题描述】:这是我用于绘图的代码
barplot(read_comments_vs_influenced, xlab='Do you usually read comments under YouTube video clips?',ylab='Count',
main=str_wrap("How far comments influence respondents' opinion for each category in reading comments under Youtube videos",width = 110)
,legend=rownames(Age_vs_platform_follow_artists),
args.legend = list(x = "topleft", cex = 0.4) )
我想让图例框水平以适合图表或使框更小而不影响图例内字体的大小 我尝试使用 ncol=3 但它给了我一个错误:ncol not a graphics argument
【问题讨论】:
【参考方案1】:这应该可行:
barplot(read_comments_vs_influenced, xlab='Do you usually read comments under YouTube video clips?',ylab='Count',
main=str_wrap("How far comments influence respondents' opinion for each category in reading comments under Youtube videos",width = 110)
)
legend("topleft", legend = rownames(Age_vs_platform_follow_artists),
ncol = 3, cex = 0.4)
也许ncol
放在括号的错误一侧?
【讨论】:
以上是关于我想让 r 条形图的图例框水平,但 ncol 不起作用的主要内容,如果未能解决你的问题,请参考以下文章
将水平线添加到 R 中 ggplot2 中的堆叠条形图,并在图例中显示
R语言ggplot2可视化绘制分组水平条形图并在条形图的各种位置添加数值标签实战
R语言使用ggpubr包的ggbarplot函数可视化水平偏差条形图(计算数值的z-score自定义填充色自定义条形边缘色自定义调色板条形图全局排序从小到大文本标签角度添加图例标签轴标签