首页 > 解决方案 > 在组合条形图中调整 1 个绘图边距?

问题描述

我正在尝试调整组合图中 1 个图的边距,以便完全显示图例。我尝试增加左侧的 par(mar= 并且它没有改变任何东西!第二个和第三个图共享相同的图例,所以我可以以某种方式减少图 2 和图 3 之间的边距,或者增加图的右边距3 所以传说显示?

这是我的代码:

par(mfrow= c(1,3))
par(mar=c(1.1, 1.1, 4.1, 8.8), xpd=TRUE) #margin lines
par(pin=c(1,2.8))  # plot areas for graphs

#graph 1 
Cmatrix<- matrix(c(2.1, 1.9, 12.4, 12.7, 70.2), nrow=5, ncol=1)
rownames(Cmatrix)<- c("NA", "Never", "1-2 Times", "Monthly", "Weekly")
Cgraph<- barplot(Cmatrix, 
    ylab= "Cumulative Percentage",
    main= "Collaboration",
    ylim= c(0,100),
    legend.text=T,
    args.legend=list(x=5.9, y=105, bty = "n"),
    space=4)

#graph 2
par(mar=c(1.1, 1.1, 4.1, 0), xpd=TRUE) #margin lines
par(pin=c(1,2.8))  # plot areas for graphs

DRmatrix<- matrix(c(1.8, 1.4, 2.5, 4.8, 16.9, 43.3, 29.4), nrow=7, ncol=1)
rownames(DRmatrix)<- c("NA", "Strongly Disagree", "Disagree", "Somewhat Disagree", "Somewhat Agree", "Agree", "Strongly Agree")  
 DRgraph<- barplot(DRmatrix, 
    xlab="Student Response", 
    main= "Discovery & Relevance",
    ylim= c(0,100))
    #legend.text=T,
    #args.legend=list(x=6, y=105, bty = "n"),
    #space=0)

#graph 3
par(mar=c(1.1, 0, 4.1, 20.1), xpd=TRUE) #margin lines
par(pin=c(1,2.8))  # plot areas for graphs

Imatrix<- matrix(c(2.2, 1.6, 5.4, 11.8, 18.9, 38, 22.1), nrow=7, ncol=1)
rownames(Imatrix)<- c("NA", "Strongly Disagree", "Disagree", "Somewhat Disagree", "Somewhat Agree", "Agree", "Strongly Agree")
Igraph<- barplot(Imatrix, 
    main= "Iteration",
    ylim= c(0,100),
    legend.text=T,
    args.legend=list(x=6.9, y=105, bty = "n"),
    space=4.5)
mtext("Average Student Responses to the LCAS Survey Categories", side = 3, line = -3, outer = TRUE)

R 输出图像

标签: r

解决方案


推荐阅读