Home > OS >  R ggplot: wrong geom_arrow direction using log scale
R ggplot: wrong geom_arrow direction using log scale

Time:12-19

I hope someone can help me with my problem:

I would like to plot some height dependent data on a logarithmic y axis. with

scale_y_continuous(expand = c(0,0), breaks = c(100,200,300,400,500,600,750,1000,1250,1500,1750,2000,2500,3000,3500,4000,5000,6000,7000,8000,9000,10000,11000,12000,13000), limit = c(min(level_h),9500), name = "Höhe in m", trans = log2_trans())

When adding wind vectors with

geom_vector(data = wind_df, aes(x=Stunde, y=level, angle = atan2(dlat(v), dlon(u, level))*180/pi,mag = Mag(v, u)), skip = 1, pivot = 0.5, show.legend = FALSE)

the angles appear with wrong directions.

Without transition to log scale wind vectors are correct. Does anyone have an idea what I am doing wrong? Is it possible that the vector angle is also log-scaled?

Thanks for your help!

With log scale: enter image description here

Without Log Scale: enter image description here

CodePudding user response:

The key is to use preserve.dir = TRUE in the call to geom_vector():

geom_vector(data = wind_df, 
            aes(x=Stunde, y=level, angle = atan2(dlat(v), dlon(u, level))*180/pi,
                mag = Mag(v, u)), 
            skip = 1, 
            pivot = 0.5, 
            show.legend = FALSE, 
            preserve.dir = TRUE)
  • Related