簡體   English   中英

R:箱形圖-如何移動x和y軸以使其可見?

[英]R: Box Plot - How to move x and y axis to be visible?

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軸標簽已消失

更新的箱線圖

您可以使用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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM