2

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 ~.)

the y-axis increments as:

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

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

1
  • Can you show a dput of your example? Try by calling Raw_Data$Velocity <- factor(Raw_Data$Velocity) Commented Jul 16, 2016 at 16:39

1 Answer 1

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)  

Followed by the command

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

which correctly displays the plot as shown in picture below
Plot

Note: changing the call to ggplot as shown below:

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

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

Sign up to request clarification or add additional context in comments.

2 Comments

It is better to include above comment in the answer, instead of in a comment.
@ProcrastinatusMaximus, included the comment inside answer as you suggested.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.