在我的Shiny应用程序中,会生成堆积条形图。列数是可变的,取决于用户的输入。当列数很少时,图例会正确显示:
但是,当列数较高时,图例会重叠图表:
请你给我一个提示,告诉我如何动态编程图例的位置,以便它始终是1.可见; 2.与图表不重叠?谢谢!
以下是图表的代码:
par(mar=c(5,4,2,14)+1,xpd=TRUE,ps=14,cex.main=1.143,cex.lab=1.143,font.lab=2)
barplot(rbind(plotdffeedingh$apercentvector,plotdffeedingh$bpercentvector,plotdffeedingh$cpercentvector,plotdffeedingh$dpercentvector,plotdffeedingh$epercentvector,plotdffeedingh$fpercentvector),
main="Feeding type composition of the herbivore nematode assemblage", xlim=c(0,length(plotdffeedingh$leveltreats)+2),
xlab="",ylab="Fraction, % of herbivore nematodes", names.arg=levels(plotdffeedingh$leveltreats),
legend.text=c("Sedentary parasites","Migratory endoparasites","Semi-endoparasites","Ectoparasites","Epidermal/root hair feeders","Algal/lichen/moss feeders"),
args.legend=list(x="right",inset=c(-0.2,0)),col=c("blue","yellow","red","grey","green","brown"),las=2)