[英]Producing line graphs with multiple lines: X-axis is out of order and y-axis scales are not in even intervals
I am working on graphing experimental data (ggplot2) involving different fertilizer rates.我正在绘制涉及不同施肥量的实验数据(ggplot2)。 I wish to note the plant response (vegetative index, or VI_Values in the data) over a series of observation dates (days after treatment, or DAT): 9, 15, 21, 27, and 35 DAT.
我想注意一系列观察日期(处理后的天数,或 DAT)上的植物反应(植物指数,或数据中的 VI_Values):9、15、21、27 和 35 DAT。 When I graph the points, my DATs (x-axis) are not in the order I want them, and my y-axis values are out of order.
当我绘制这些点时,我的 DAT(x 轴)不是我想要的顺序,我的 y 轴值是乱序的。 How can I fix these two things, and how can I restructure the y-axis to increase in even intervals?
我怎样才能解决这两个问题,我怎样才能重组 y 轴以增加均匀的间隔? Preferable showing only whole numbers on the y-axis (or at least just a few decimals past the whole number).
最好在 y 轴上只显示整数(或至少在整数后面几位小数)。
Running this code...运行此代码...
ggplot(data=dataset, aes(x=DAT, y=SR, group = Rate, colour = as.factor(Rate)))+
geom_line()+
geom_point()
...produces the following graph: ...产生以下图表:
I need to order the x-axis as follows: 9, 15, 21, 27, 35 DAT, and I definitely want to clean up that y-axis.我需要按如下方式对 x 轴进行排序:9、15、21、27、35 DAT,并且我肯定想清理那个 y 轴。
Here's the dataset:这是数据集:
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))
dput output:输入 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))
For setting your own values on the x-axis, use scale_x_discrete
function:要在 x 轴上设置您自己的值,请使用
scale_x_discrete
function:
scale_x_discrete(limits = c(9, 15, 21, 27, 35))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.