两个y轴(左:ws;右:wd),一个x轴(月),由监测站构成

时间:2018-01-09 02:38:10

标签: r ggplot2

我的数据示例:

wd <- c(60, 68, 125,103, 129, 188, 183, 187, NaN, NaN, NaN, 55,349, 290, 175, 178, 181, 172, 143, 161, 154, 156, 165, 260)
ws <- c(1.9, 0.8, 0.5, 0.6, 0.6, 1.24, 0.82, 0.92, NaN, NaN, NaN, 0.5, 0.3, 0.3, 0.64, 0.39, 0.52, 1, 0.96, 1.12, 1.82, 1.53, 0.7, 0.2)
Month <- c("Jan", "Feb", "Mar", "Apr","May" ,"Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
variable <- c("CUA", "CUA","CUA","CUA","CUA","CUA","CUA","CUA","CUA","CUA","CUA","CUA", "MER", "MER","MER", "MER", "MER","MER", "Mer""MER", "MER","MER", "MER", "MER","MER")
df <- data.frame(Month, variable, wd, ws)

我想获得一个带有两个y轴(左:ws;右:wd),一个x轴(月),监测站(变量)的面积

我已经有了第一个y轴

ggplot(df, aes(x=Month, y=ws, group=variable)) + 
  geom_line() + 
  geom_point() + 
  facet_wrap(~variable) + 
  theme(axis.text.x = element_text(angle = 90, hjust = 1)) + 
  ylab("Speed") 

ws plot

我只是想用wd值添加第二个y轴。

感谢您的帮助

0 个答案:

没有答案