0

Example of my data:

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)

I would like to get one plot with two y-axis (left:ws; right:wd), one x-axis (Month), facet by monitoring station (variable)

I already have the first y-axis

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

and I just want to add the second y-axis with wd values.

Thank you for the help

Richard Telford
  • 9,558
  • 6
  • 38
  • 51
Yair
  • 1
  • 2
  • 1
    Suggested duplicate: [Plot with 2 y axes, one y axis on the left, and another y axis on the right](https://stackoverflow.com/q/3099219/903061) – Gregor Thomas Jan 09 '18 at 02:56
  • @jesstme `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")` – Yair Jan 09 '18 at 03:28

0 Answers0