按降序排列 y 轴

Arranging y-axis in descending order

提问人:Jackie Reuder 提问时间:11/17/2023 最后编辑:Jon SpringJackie Reuder 更新时间:11/22/2023 访问量:36

问:

我在 R 中有一个算盘图,其 y 轴从底部降序排列。我需要它从顶部下降。abacus_plot() 使用基本 plot() 变量。看似直截了当,但我却空手而归。我的代码:

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)

目前剧情:

enter image description here

R 绘图 YAXIS

评论

0赞 Jon Spring 11/17/2023
来自什么包装?abacus_plot
0赞 Jackie Reuder 11/17/2023
glatos 软件包
0赞 Jon Spring 11/17/2023
好吧,看起来这不是来自 CRAN,你能引导我们到那个包是从哪里下载的吗?(没有什么能阻止世界上存在多个同名的软件包,有时也会发生这种情况。
0赞 Jackie Reuder 11/17/2023
github.com/ocean-tracking-network/glatos/wiki/......

答:

0赞 Chris Holbrook 11/22/2023 #1

Glatos::abacus_plot 将 Y 轴值视为文本,默认情况下,它沿 Y 轴从下到上按反向字母顺序对级别进行排序。尽管使用纬度等数值似乎有悖常理,但您只需要指定唯一的 y 轴级别(包括从下到上的打印顺序)并通过参数将这些级别传递给abacus_plot。这在 ?abacus_plot 中进一步解释。locations

因此,要回答您的问题,请尝试:

# 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)