将一个表的点绘制到另一个表的折线图上

Plot points of one table onto the line graph of another table

提问人:Stefanie van den Berg 提问时间:10/30/2023 更新时间:10/30/2023 访问量:28

问:

我绘制了折线图和数据的散点图。 折线图描绘了我在几个月内进行的连续测量。 类似粪便的图显示了我手动进行的测量,以检查连续数据的可靠性。

因此,我想将手部测量的点绘制到折线图上,看看它们是否重叠。 是否可以将这些图合并为一个?

感谢您抽出宝贵时间接受采访。

特此,到目前为止,我的代码...

> dput(head(MW3, 10))
structure(list(MonitoringPoint = c("Pb 3-1", "Pb 3-1", "Pb 3-1", 
"Pb 3-1", "Pb 3-1", "Pb 3-1", "Pb 3-1", "Pb 3-1", "Pb 3-1", "Pb 3-1"
), SerialNumber = c("R1453", "R1453", "R1453", "R1453", "R1453", 
"R1453", "R1453", "R1453", "R1453", "R1453"), Date_Time = structure(c(1680804000, 
1680807600, 1680811200, 1680814800, 1680818400, 1680822000, 1680825600, 
1680829200, 1680832800, 1680836400), tzone = "UTC", class = c("POSIXct", 
"POSIXt")), Date = structure(c(1680739200, 1680739200, 1680739200, 
1680739200, 1680739200, 1680739200, 1680825600, 1680825600, 1680825600, 
1680825600), tzone = "UTC", class = c("POSIXct", "POSIXt")), 
    Time = structure(c(-2209010400, -2209006800, -2209003200, 
    -2208999600, -2208996000, -2208992400, -2209075200, -2209071600, 
    -2209068000, -2209064400), tzone = "UTC", class = c("POSIXct", 
    "POSIXt")), Pressure = c(1089.85, 1090.025, 1090.375, 1090.725, 
    1091.075, 1091.775, 1092.35833333333, 1093.23333333333, 1093.75833333333, 
    1094.45833333333), Temperature = c(8.29, 8.28666666666667, 
    8.28333333333334, 8.28333333333334, 8.28, 8.28, 8.28, 8.28, 
    8.27666666666667, 8.27333333333333), Conductivity = c(1209, 
    1209, 1209, 1208, 1209, 1210, 1215, 1217, 1220, 1222), TOC_MV_cm = c(4, 
    4, 4, 4, 4, 4, 4, 4, 4, 4), WaterLevel_TOC_cm = c(64.0600000000002, 
    63.7829999999999, 63.433, 63.0830000000001, 62.7329999999999, 
    61.9309999999998, 61.6536666666666, 60.9826666666665, 60.3556666666668, 
    59.7576666666664), WaterLevel_MV_cm = c(60.0600000000002, 
    59.7829999999999, 59.433, 59.0830000000001, 58.7329999999999, 
    57.9309999999998, 57.6536666666666, 56.9826666666665, 56.3556666666668, 
    55.7576666666664), WaterLevel_MV_m = c(0.600600000000002, 
    0.597829999999999, 0.59433, 0.590830000000001, 0.587329999999999, 
    0.579309999999998, 0.576536666666666, 0.569826666666665, 
    0.563556666666668, 0.557576666666664), PB_NAP_MV_m = c(77.016, 
    77.016, 77.016, 77.016, 77.016, 77.016, 77.016, 77.016, 77.016, 
    77.016), WaterLevel_NAP_m = c(76.4154, 76.41817, 76.42167, 
    76.42517, 76.42867, 76.43669, 76.4394633333333, 76.4461733333333, 
    76.4524433333333, 76.4584233333333), WaterLevelReference = c("WATER HEAD (TOC-CL)", 
    "WATER HEAD (TOC-CL)", "WATER HEAD (TOC-CL)", "WATER HEAD (TOC-CL)", 
    "WATER HEAD (TOC-CL)", "WATER HEAD (TOC-CL)", "WATER HEAD (TOC-CL)", 
    "WATER HEAD (TOC-CL)", "WATER HEAD (TOC-CL)", "WATER HEAD (TOC-CL)"
    ), Salinity = c(0.601516, 0.601516, 0.601516, 0.600992, 0.601516, 
    0.60204, 0.60466, 0.605708, 0.60728, 0.608328)), row.names = c(NA, 
-10L), class = c("tbl_df", "tbl", "data.frame"))



> dput(head(Manual_waterlevel_3, 10))
structure(list(Locatie = c("3_1", "3_1", "3_1", "3_1", "3_1", 
"3_1"), Datum = structure(c(1681257600, 1682380800, 1683849600, 
1684800000, 1686873600, 1696896000), tzone = "UTC", class = c("POSIXct", 
"POSIXt")), `Pb t.o.v. mv (cm)` = c(4, 4, 4, 4, 4, 4), `H2O t.o.v. Pb (of dergelijke) (cm)` = c(50, 
56, 47, 66, 107, 61), `H2O t.o.v. Pb (of dergelijke) (m)` = c(0.5, 
0.56, 0.47, 0.66, 1.07, 0.61), `H2O t.o.v. mv (cm)` = c(46, 52, 
43, 62, 103, NA), `H2O t.o.v. mv (m)` = c(0.46, 0.52, 0.43, 0.62, 
1.03, NA), `NAP mv (m)` = c(77.016, 77.016, 77.016, 77.016, 77.016, 
77.016), H20_NAP = c(76.556, 76.496, 76.586, 76.396, 75.986, 
76.446)), row.names = c(NA, -6L), class = c("tbl_df", "tbl", 
"data.frame"))

# Import data set of the diver measurements
library(readxl)
MW3 <- read_excel("C:/Users/923721/OneDrive - Royal HaskoningDHV/Internship documents/Data_Weustenrade/Waterstanden/MW3.xlsx")

# Obtain the average water level per day (removing the time component)
Water_level_perday <- MW3 %>%
  mutate(date = floor_date(Date)) %>%
  group_by(Date) %>%
  summarize(mean_waterlevel = mean(WaterLevel_NAP_m))

# Plot diver measurement data
Diver <- ggplot(Water_level_perday, aes(x = Date, y = mean_waterlevel)) + geom_line()  + labs(x = "Time", y = "Water level_NAP (m)") + theme_classic() 

# Load data set of the manual measurements
library(readxl)
Manual_waterlevel_3 <- read_excel("C:/Users/923721/OneDrive - Royal HaskoningDHV/Internship documents/Data_Weustenrade/Waterstanden/Manual_waterlevel_3.xlsx")

# Plot manual measurement data
Manual <- ggplot(Manual_waterlevel_3, aes(x = Datum, y = H20_NAP)) + geom_point()  + labs(x = "Time", y = "Water level_NAP (m)") + theme_classic() 
R 绘图 线

评论

0赞 Limey 10/30/2023
是的,它是。只需提供第二个数据集的名称作为用于绘制手部数据的调用的参数即可。(您可能还需要设置 。datageom_xxxxinherit.aes = FALSE
0赞 Stefanie van den Berg 10/30/2023
感谢您的回复。这会是什么样子?换句话说,我该如何写出来?

答:

1赞 Limey 10/30/2023 #1

正如我在评论中所写的,要组合基于两个不同数据框的绘图,您只需在每次调用中为参数提供适当的值。通常,该值来自管道的开头或对 的调用。同样,您也可以移动各种。datageom_xxxxdataggplot()aes()

根据您的数据并边做边总结,dputMW3

Water_level_perday %>% 
  ggplot(aes(x = Date, y = mean_waterlevel)) + 
  geom_line()  + 
  geom_point(data = Manual_waterlevel_3, aes(x = Datum, y = H20_NAP))  + 
  labs(x = "Time", y = "Water level_NAP (m)") + 
  theme_classic() 

enter image description here