格子图面板的指定顺序 [英] Specifing order of lattice plot panels

查看:62
本文介绍了格子图面板的指定顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经查看了关于此主题的两个类似问题,但是在两个问题中都找不到我想要的答案. as.table函数将字母顺序从左下角更改为左上角,但是对组中窗格的顺序没有任何作用.

I have looked at the two similar questions on this topic but do not find the answer I'm looking for in either of the two. The as.table function alters the alphabetic sequence from starting in the lower left to starting in the upper left but does nothing about the order of panes within the group.

数据(我的客户专有)具有站号,该站号是字母和数字的组合.如果在要绘制的所有站点的组中有一系列站点具有相同的首字母,则它们将按第一位数字而不是人类计数的方式排序.例如,SW-1,SW-10,SW-11,SW-2,SW-3.我想要按SW-1,SW-2,SW-3,SW-10,SW-11的顺序排列.我使用的代码是:

The data (which are proprietary to my client) have station identifications that are a combination of letters and numbers. When there is a series of sites with the same initial letters within the group of all sites being plotted, they sort by first digit rather than the way we humans count. For example, SW-1, SW-10, SW-11, SW-2, SW-3. I would like them in the order SW-1, SW-2, SW-3, SW-10, SW-11. The code I use is:

 xyplot(as.d$quant ~ as.d$sampdate | as.d$site, ylim=range(as.d$quant), xlim=range(as.d$sampdate), 
 main='Arsenic By Time', ylab='Concentraion (mg/L)', xlab='Time')

我不知道如何在生成的图上附加.pdf,但是如果有人向我展示了如何做,便会这样做.

I do not know how to attach a .pdf of the resulting plot but will do so if someone shows me how to do this.

推荐答案

您需要按期望的顺序指定该因子变量的级别.正如您所注意到的,默认值为Lexigraphic:

You need to specify the levels of that factor variable in the sequence you expect. The default is lexigraphic as you noticed:

xyplot(as.d$quant ~ as.d$sampdate | factor( as.d$site, 
                                            levels=1:length(unique(as.d$site))) , 
         ylim=range(as.d$quant),   xlim=range(as.d$sampdate), 
         main='Arsenic By Time', ylab='Concentration (mg/L)', xlab='Time')

根据问题的当前状况,您可能需要:

Based on how the question currently stands, you might need:

require(gtools)
xyplot(as.d$quant ~ as.d$sampdate | factor( as.d$site, 
                                  levels=mixedsort( as.character(unique(as.d$site)) ) ) , 
         ylim=range(as.d$quant),   xlim=range(as.d$sampdate), 
         main='Arsenic By Time', ylab='Concentration (mg/L)', xlab='Time')

这篇关于格子图面板的指定顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆