3 つの列 (y1、y2、x) を含むデータフレーム (df1) があります。y1、x と y2、x の間に箱ひげ図グラフをプロットすることができました。2 つの列 A、x を含む別のデータフレーム (df2) があります。折れ線グラフ (A,x) をプロットし、箱ひげ図に追加したいと考えています。両方のデータフレームの変数 x は軸アクセスですが、値が異なることに注意してください。factor(x) に基づいて、データフレームとプロットの両方を結合して再形成しようとしました... 1 つのグラフに 3 つの箱ひげ図があります。df2 を線として、df1 を箱ひげ図として 1 つのグラフにプロットする必要があります。
df1 <- structure(list(Y1 = c(905L, 941L, 744L, 590L, 533L, 345L, 202L,
369L, 200L, 80L, 200L, 80L, 50L, 30L, 60L, 20L, 30L, 30L), Y2 = c(774L,
823L, 687L, 545L, 423L, 375L, 249L, 134L, 45L, 58L, 160L, 60L,
20L, 40L, 20L, 26L, 19L, 27L), x = c(10L, 10L, 10L, 20L, 20L,
20L, 40L, 40L, 40L, 50L, 50L, 50L, 70L, 70L, 70L, 90L, 90L, 90L
)), .Names = c("Y1", "Y2", "x"), row.names = c(NA, -18L), class = "data.frame")
df2 <- structure(list(Y3Line = c(384L, 717L, 914L, 359L, 241L, 265L,
240L, 174L, 114L, 165L, 184L, 96L, 59L, 60L, 127L, 54L, 31L,
44L), x = c(36L, 36L, 36L, 56L, 56L, 56L, 65L, 65L, 65L, 75L,
75L, 75L, 85L, 85L, 85L, 99L, 99L, 99L)), .Names = c("A",
"x"), row.names = c(NA, -18L), class = "data.frame")
df_l <- melt(df1, id.vars = "x")
ggplot(df_l, aes(x = factor(x), y =value, fill=variable )) +
geom_boxplot()+
# here I'trying to add the line graph from df2
geom_line(data = df2, aes(x = x, y=A))
助言がありますか?