Rstudio绘图,如何在图上拟合图例和轴标签

时间:2019-11-27 20:24:32

标签: r plot

嗨,我正在R中从事一项新工作,正在创建一个显示样品污染水平的箱形图。我的图形看起来像我想要的样子,但是我无法让图例移动到侧面而不会消失,并且x轴标签从底部掉下来。

我的代码如下:

#adds padding to the inner margin of the graph, allows legend and labels to fit
par(mar=c(10,5,3,10)) 

stackedGraphGOOD = barplot(as.matrix(goodKrakenData), 
                              col = c("DODGERBLUE", "GREEN3", "RED"), 
                              ylab = "Percent", border = NA, axis.lty = 1, cex.axis = 1,  
                              main = "Kraken Quality Percentages", 
                              legend.text = c("Unclassified", "Family", "Other"), 
                              args.legend = list(x = 14, bty='y'), las = 2)
         #allows me to adjust the placement of the x-axis label
         title(xlab = "Animal ID", line = 9) 

然后我得到一个看起来像这样的图:

GoodGraph

我需要调整图表的内部和外部页边距以使其正确显示

taxonomy ID1 ID2 ID3
unclassified 19 5 10
Other 0.0003 0.0006 0.08
primaryFamily 80.9997 94.9994 89.92

1 个答案:

答案 0 :(得分:0)

我设法通过调整图表的边距来解决问题。 通过添加行

par(mar = c(10,5,3,10))#将填充添加到图形的内部边缘,允许图例和标签适合

开头和

title(xlab =“动物ID”,第9行)#允许我调整x轴标签的位置

最后按

调整x轴标签 在https://www.r-graph-gallery.com/74-margin-and-oma-cheatsheet.html

找到了答案
相关问题