在条形图中正确显示图例

我想在y轴下显示图例,而不是显示为垂直列表,而是显示为水平列表。如果不可能,您是否有任何解决方案可提出,以使图例不与图形重叠? 我找到了解决此类问题的答案,但我不理解。

meute1 = c(78.6,9.7,0.6,11.1)
meute2 = c(60.8,35.7,0.2,3.3) 
meute3 = c(61.2,16.5,2.3,20.0) 
meute4 = c(54.6,10.7,9.8,24.9)
meutes=cbind(meute1,meute2,meute3,meute4)
coul= brewer.pal(n = length(meute1),name = 'Set3')

barplot(height = meutes,col=coul,horiz=T,names.arg = c("Meute 1","Meute 2","Meute 3","Meute 4"),legend.text = c("Ongulés sauvage","Petits et moyens mammifères","micro-mammifères","Appâts"),args.legend = list(x = "topright"),las=1)

在条形图中正确显示图例

tianshi123456 回答:在条形图中正确显示图例

我认为您正在寻找类似以下的内容。您只需要向args.legend添加一些参数,即horiz = T将其设置为水平,x将图例移至图的底部,inset将图例移至向下,然后cex更改字体大小。我无法使颜色起作用,但您明白了:

barplot(height = meutes,horiz=T,names.arg = c("Meute 1","Meute 2","Meute 3","Meute 4"),legend.text = c("Ongulés sauvage","Petits et moyens mammifères","Micro-mammifères","Appâts"
                        ),args.legend = list(x = "bottom",# <- move legend to bottom
                           inset = c(0,-.25),# <- move legend outside plot
                           horiz = T,# <- make legend horizontal
                           cex = .8),# <- change legend font size
        las=1
        )

enter image description here

,

使用xpd=TRUE可以将图例放置在图外,例如

# Add extra space at the bottom of plot area; change clipping to figure
par(mar=c(8.1,4.1,2.1),xpd=TRUE)
library(RColorBrewer)

barplot(height = meutes,col=coul,"Appâts"),text.width = c(25,30,17),bty='n',horiz = T,inset=-0.2,cex = .8),las=1)

enter image description here

本文链接:https://www.f2er.com/3165313.html

大家都在问