rplotyaxisglatos

Arranging y-axis in descending order


I have an abacus plot in R that has the y-axis in descending order from the bottom. I need it descending from the top. The abacus_plot() uses base plot() variables. Seems straight forward, but I am coming up empty. My code:

library(glatos)
abacus_plot(detections_w_events,
            location_col= 'deploy_lat', ylab = 'Latitude',
            main='Detections by Station', x_res = "12 weeks", x_format = "%b-%y",
            col = detections_w_events$color)

The plot currently:

enter image description here


Solution

  • glatos::abacus_plot treats the y-axis values as text and by default it sorts levels in reverse alphabetical order along the y-axis from bottom to top. Although it seems counter-intuitive with a numeric value like latitude, you simply need to specify the unique y-axis levels (including order to be printed from bottom to top) and pass those to abacus_plot via the locations argument. This is explained further in ?abacus_plot.

    So to answer your question, try:

    # make vector of y-levels to display (with desired order, bottom-to-top along y)
    my_locs <- sort(unique(detections_w_events$deploy_lat))
    
    abacus_plot(detections_w_events,
                location_col= 'deploy_lat', 
                locations = my_locs,
                ylab = 'Latitude',
                main='Detections by Station', x_res = "12 weeks", x_format = "%b-%y",
                col = detections_w_events$color)