简体   繁体   English

生成多条线的折线图:X 轴无序且 y 轴刻度不等间隔

[英]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.

相关问题 R, ggplot - 图形共享相同的 y 轴但具有不同的 x 轴比例 - R, ggplot - Graphs sharing the same y-axis but with different x-axis scales 如何在给定 x 轴的情况下为多个图形查找 y 轴值 - How to find y-axis values given x-axis for multiple graphs 在y轴上绘制单个变量,在x轴上绘制多个变量 - Plotting a single variable on the y-axis and multiple on the x-axis R基图:在1个坐标图的x轴和y轴上绘制2个密度图 - R baseplot :plotting 2 density plots in 1 plot cand hanging scales for x-Axis and y-Axis 如何在X轴保持不变的情况下将Y轴的间隔加倍 - How to double the intervals in Y-axis while X-axis remains same R ggplot2:如何使x轴线不与y轴重叠? - R ggplot2: how to make x-axis lines not overlapping y-axis? R程序-如何避免ggplot在x轴和y轴上重新排序 - R program-how to avoid ggplot re-order in both x-axis and y-axis 有人可以帮我弄清楚为什么我的y轴和x轴标签没有显示吗? - Can anybody help figure out why my labels for the y-axis and x-axis are not appearing? 在 R 基础 plot 和 GGPlot2 中的 x 轴和 y 轴上显示相应的虚线 - Show corresponding dash line on x-axis and y-axis in R base plot and GGPlot2 如何在以年为x轴和y轴为计数的R中绘制线形图? - How to plot line graph in R with years as x-axis and y-axis as count?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM