dplyr の spread() 関数を使用して作成したデータ フレームに基づいて、いくつかの相関プロットを作成しようとしています。スプレッド関数を使用すると、新しいデータ フレームに NA が作成されました。データ フレームには、さまざまな期間のさまざまなパラメーターの濃度値が含まれていたため、これは理にかなっています。
元のデータ フレームのスクリーンショットの例を次に示します。
スプレッド関数を使用すると、次のようなデータ フレームが得られました (サンプル データ):
structure(list(orgid = c("11NPSWRD", "11NPSWRD", "11NPSWRD",
"11NPSWRD", "11NPSWRD", "11NPSWRD", "11NPSWRD", "11NPSWRD", "11NPSWRD",
"11NPSWRD", "11NPSWRD", "11NPSWRD", "11NPSWRD", "11NPSWRD", "11NPSWRD",
"11NPSWRD", "11NPSWRD", "11NPSWRD", "11NPSWRD", "11NPSWRD"),
locid = c("11NPSWRD-MORR_NPS_PR2", "11NPSWRD-MORR_NPS_PR2",
"11NPSWRD-MORR_NPS_PR2", "11NPSWRD-MORR_NPS_PR2", "11NPSWRD-MORR_NPS_PR2",
"11NPSWRD-MORR_NPS_PR2", "11NPSWRD-MORR_NPS_PR2", "11NPSWRD-MORR_NPS_PR2",
"11NPSWRD-MORR_NPS_PR2", "11NPSWRD-MORR_NPS_PR2", "11NPSWRD-MORR_NPS_PR2",
"11NPSWRD-MORR_NPS_PR2", "11NPSWRD-MORR_NPS_PR2", "11NPSWRD-MORR_NPS_PR2",
"11NPSWRD-MORR_NPS_PR2", "11NPSWRD-MORR_NPS_PR2", "11NPSWRD-MORR_NPS_PR2",
"11NPSWRD-MORR_NPS_PR2", "11NPSWRD-MORR_NPS_PR2", "11NPSWRD-MORR_NPS_PR2"
), stdate = structure(c(9891, 9891, 9891, 9920, 9920, 9920,
9949, 9949, 9949, 9978, 9978, 9978, 10011, 10011, 10011,
10067, 10067, 10073, 10073, 10073), class = "Date"), sttime = structure(c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), class = c("hms",
"difftime"), units = "secs"), valunit = c("uS/cm", "mg/l",
"mg/l", "uS/cm", "mg/l", "mg/l", "uS/cm", "mg/l", "mg/l",
"uS/cm", "mg/l", "mg/l", "uS/cm", "mg/l", "mg/l", "uS/cm",
"mg/l", "uS/cm", "mg/l", "mg/l"), swqs = c("FW2-TP", "FW2-TP",
"FW2-TP", "FW2-TP", "FW2-TP", "FW2-TP", "FW2-TP", "FW2-TP",
"FW2-TP", "FW2-TP", "FW2-TP", "FW2-TP", "FW2-TP", "FW2-TP",
"FW2-TP", "FW2-TP", "FW2-TP", "FW2-TP", "FW2-TP", "FW2-TP"
), WMA = c(6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L), year = c(1997L, 1997L, 1997L,
1997L, 1997L, 1997L, 1997L, 1997L, 1997L, 1997L, 1997L, 1997L,
1997L, 1997L, 1997L, 1997L, 1997L, 1997L, 1997L, 1997L),
Chloride = c(NA, 35, NA, NA, 45, NA, NA, 30, NA, NA, 30,
NA, NA, 30, NA, NA, NA, NA, 35, NA), `Specific conductance` = c(224,
NA, NA, 248, NA, NA, 204, NA, NA, 166, NA, NA, 189, NA, NA,
119, NA, 194, NA, NA), `Total dissolved solids` = c(NA, NA,
101, NA, NA, 115, NA, NA, 96, NA, NA, 79, NA, NA, 89, NA,
56, NA, NA, 92)), .Names = c("orgid", "locid", "stdate",
"sttime", "valunit", "swqs", "WMA", "year", "Chloride", "Specific conductance",
"Total dissolved solids"), row.names = c(NA, 20L), class = "data.frame")
私が抱えている問題は、相関プロットを作成しようとすると、1つの点しかないプロットが得られることです..これは、データフレームにNAがあるためだと思います..しかし、NAをフィルタリングしようとすると、観測値が0のデータフレームが表示されます..どんな助けでも大歓迎です!!
相関プロットを作成するコード例:
plot1<-ggplot(data=df,aes(x="Specific conductance",y="Chloride"))+
geom_smooth(method = "lm", se=FALSE, color="black", formula = y ~ x)+
geom_point()