簡體   English   中英

生成多條線的折線圖:X 軸無序且 y 軸刻度不等間隔

[英]Producing line graphs with multiple lines: X-axis is out of order and y-axis scales are not in even intervals

我正在繪制涉及不同施肥量的實驗數據(ggplot2)。 我想注意一系列觀察日期(處理后的天數,或 DAT)上的植物反應(植物指數,或數據中的 VI_Values):9、15、21、27 和 35 DAT。 當我繪制這些點時,我的 DAT(x 軸)不是我想要的順序,我的 y 軸值是亂序的。 我怎樣才能解決這兩個問題,我怎樣才能重組 y 軸以增加均勻的間隔? 最好在 y 軸上只顯示整數(或至少在整數后面幾位小數)。

運行此代碼...

ggplot(data=dataset, aes(x=DAT, y=SR, group = Rate, colour = as.factor(Rate)))+
  geom_line()+
  geom_point()

...產生以下圖表:

在此處輸入圖像描述

我需要按如下方式對 x 軸進行排序:9、15、21、27、35 DAT,並且我肯定想清理那個 y 軸。

這是數據集:

dataset <- data.frame(Cultivar = c("pio", "pio", "pio", "pio", "pio", "pio", 
"pio", "pio", "pio", "pio", "pio", "pio", "pio", "pio", "pio", "pio", "pio", "pio", "pio", "pio"),
                      Rate = c(0,
                               1,
                               4,
                               8,
                               0,
                               1,
                               4,
                               8,
                               0,
                               1,
                               4,
                               8,
                               0,
                               1,
                               4,
                               8,
                               0,
                               1,
                               4,
                               8),
                      DAT = c(9,
                              9,
                              9,
                              9,
                              15,
                              15,
                              15,
                              15,
                              21,
                              21,
                              21,
                              21,
                              27,
                              27,
                              27,
                              27,
                              35,
                              35,
                              35,
                              35),
                      SR = c(5.443664,
                                   4.91077766666667,
                                   3.615712,
                                   2.81359,
                                   10.4675316666667,
                                   9.65146,
                                   7.646191,
                                   7.138025,
                                   8.24739066666667,
                                   7.85872166666667,
                                   6.14369533333333,
                                   5.83806466666667,
                                   13.3828463333333,
                                   12.3525363333333,
                                   11.0249503333333,
                                   10.5858046666667,
                                   13.8856,
                                   12.7933703333333,
                                   10.966898,
                                   11.194905),
                      Error = c(0.138439743861123,
                                0.445183750289448,
                                0.716154295933728,
                                0.209298947911833,
                                0.485569061785356,
                                0.870274032427143,
                                0.92619068130992,
                                0.896274542793855,
                                0.225475438285661,
                                0.863429277269874,
                                0.522656438625583,
                                0.827932691360905,
                                0.741721042845025,
                                1.2532188075592,
                                1.01358403281381,
                                1.16022067736693,
                                0.262671210179824,
                                1.02721331514967,
                                0.626616072499209,
                                0.669908769))

輸入 output:

structure(list(Cultivar = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "pio", class = "factor"), 
    Rate = c(0, 1, 4, 8, 0, 1, 4, 8, 0, 1, 4, 8, 0, 1, 4, 8, 
    0, 1, 4, 8), DAT = c(9, 9, 9, 9, 15, 15, 15, 15, 21, 21, 
    21, 21, 27, 27, 27, 27, 35, 35, 35, 35), SR = c(5.443664, 
    4.91077766666667, 3.615712, 2.81359, 10.4675316666667, 9.65146, 
    7.646191, 7.138025, 8.24739066666667, 7.85872166666667, 6.14369533333333, 
    5.83806466666667, 13.3828463333333, 12.3525363333333, 11.0249503333333, 
    10.5858046666667, 13.8856, 12.7933703333333, 10.966898, 11.194905
    ), Error = c(0.138439743861123, 0.445183750289448, 0.716154295933728, 
    0.209298947911833, 0.485569061785356, 0.870274032427143, 
    0.92619068130992, 0.896274542793855, 0.225475438285661, 0.863429277269874, 
    0.522656438625583, 0.827932691360905, 0.741721042845025, 
    1.2532188075592, 1.01358403281381, 1.16022067736693, 0.262671210179824, 
    1.02721331514967, 0.626616072499209, 0.669908769)), class = "data.frame", row.names = c(NA, 
-20L))

要在 x 軸上設置您自己的值,請使用scale_x_discrete function:

scale_x_discrete(limits = c(9, 15, 21, 27, 35))

暫無
暫無

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

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