数字轴标签顺序错误 [英] Numeric axis labels in incorrect order

查看:44
本文介绍了数字轴标签顺序错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下生成的数据框,称为Raw_Data:

I have the following generated data frame called Raw_Data:

    Time Velocity Type
1    10        1    a
2    20        2    a
3    30        3    a
4    40        4    a
5    50        5    a
6    10        2    b
7    20        4    b
8    30        6    b
9    40        8    b
10   50        9    b
11   10        3    c
12   20        6    c
13   30        9    c
14   40       11    c
15   50       13    c

在绘制每种类型时,具有以下内容:

When plotting each Type, with the following:

ggplot(Raw_Data, aes(x=Time, y=Velocity))+geom_point() + facet_grid(Type ~.)

y轴的增量为:

1, 11, 13, 2, 3, 4, 5, 6, 7, 8, 9

y轴标签应该井井有条-为什么11和12在1之后出现?

The y-axis labels should be in order - why has 11 and 12 appeared after 1?

推荐答案

我已使用您的示例数据按如下方式创建了数据框:

I have created the data frame as follows using your sample data:

mydata <- read.table(text="Time Velocity Type
1    10        1    a
2    20        2    a
3    30        3    a
4    40        4    a
5    50        5    a
6    10        2    b 
7    20        4    b
8    30        6    b
9    40        8    b
10   50        9    b
11   10        3    c
12   20        6    c
13   30        9    c
14   40       11    c
15   50       13    c", header=TRUE)  

后跟命令

ggplot(mydata, aes(x=Time, y=Velocity))+geom_point() + facet_grid(Type ~.)  

可以正确显示绘图,如下图所示

which correctly displays the plot as shown in picture below

注意:将呼叫更改为 ggplot ,如下所示:

Note: changing the call to ggplot as shown below:

ggplot(mydata, aes(x=Time, y=as.character(Velocity))) +
  geom_point() +
  facet_grid(Type ~.)

重现您提到的问题.因此,您需要将 Velocity 变量转换为适当的类型,例如您的情况下的 integer .

reproduces the problem you mentioned. So you need to convert the Velocity variable to appropriate type i.e. integer in your case.

这篇关于数字轴标签顺序错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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