ana1$B<-factor(ana1$Burn,c("C","N","L","S"))
with(ana1,boxplot(Time~ana1$B, ylab = "Infiltration Rate (mm/h) " , xlab ="Burn Treatment", las = 2, par(mar = c(12, 5, 4, 2)+0.1), names = c( "Control" , "Not burned since 1954" , "Long rotation burn" , "Short rotation burn" ) ) )
嗨,这是我当前的代码,它会创建受我的旋转标签阻碍的轴标题。有没有人知道如何跨越和向下移动两个轴标题?
我真的很挣扎,虽然解决方案可能很容易!
所以我已经提醒了代码,但是现在x轴标签完全脱离了盒子图
ana1$B<-factor(ana1$Burn,c("C","N","L","S"))
with(ana1,boxplot(Time~ana1$B, ylab = "Infiltration Rate (mm/h) " , xlab = "", las = 2, par(mar = c(12, 4, 4, 1)+0.1), title("Burn Treatment", line = 10), names = c( "Control" , "Not burned since 1954" , "Long rotation burn" , "Short rotation burn" ) ) )
参数已更改,但x轴标签已消失
答案 0 :(得分:0)
您可以使用title
手动绘制轴标题,并通过line
参数调整其位置。例如,对于x轴,您可以执行
par(mar = c(12, 4, 4, 2) + 0.1);
boxplot(df, xlab = "", las = 2);
title(xlab = "Burn Treatment", line = 10);
您可以使用par(mar = ...)
增加地块边距。您可能需要调整数据的参数par(mar = ...)
和title(..., line = ...)
。
df <- data.frame(
'Control' = rnorm(100),
'Not burned since 1954' = rnorm(100),
'Long rotation burn' = rnorm(100),
'Short rotation burn' = rnorm(100))
以下内容适用于您的数据:
par(mar = c(12, 4, 4, 1) + 0.1); # This sets the plot margins
with( # Draw the boxplot
ana1,
boxplot(
Time ~ B,
ylab = "Infiltration Rate (mm/h) " ,
xlab = "",
las = 2,
names = c("Control" , "Not burned since 1954" , "Long rotation burn" , "Short rotation burn")));
title(xlab = "Burn Treatment", line = 10); # Add x axis title
您可能需要使用line = 10
并尝试不同的值;情节边缘同样如此。 mar = c(12, 4, 4, 2)
中的第一个数字给出了底部边距,有关详细信息,请参阅?par
。