使用R中的ggplot绘制主要和次要y轴上的点和线图

时间:2017-11-08 19:18:45

标签: r ggplot2

我有下表。我需要将主要y轴上的“Area”绘制为x轴上带有“Weeks”的点。对于相同的x轴,我需要在次y轴上绘制“SM9_5”。我有我的代码,但没有正确的绘图。

任何想法都表示赞赏。

感谢。

YEAR   Week  Area  SM9_5   sum  percent COUNTY         
2002   9-2   250   212.2    250     10.2  125
2002   10-1  300   450.2    550     22.5  125
2002   10-2  100   150.2    650    100.0  125 
2002   9-3   50    212.2    250     10.2   15
2002   10-1  30    450.2    550     22.5   15
2002   10-2  10    150.2    650    100.0   15 
2003   9-2   12    112.2     12     20.2  150
2003   10-1  15    350.2     27     82.5  150
2003   10-2  16    650.2     43    100.0  150

gg <- gg + geom_point(aes(y = Area, colour = "Area"))
gg <- gg + geom_line(aes(y = SM9_1, colour = "Sep_SM_9-1"))
gg <- gg + scale_y_continuous(sec.axis = sec_axis(~., name = "Soil Moisture"))
gg <- gg + scale_colour_manual(values = c("blue","red"))
gg <- gg + facet_wrap(~COUNTY, 2, scales = "fixed")
gg <- gg + labs(y = "Area",
                x = "Weeks",
                colour = "Parameter")
plot(gg)

我的情节如下所示。

enter image description here

enter image description here

0 个答案:

没有答案