Reputation:
I have attached a screenshot of the problem im facing.
Basically my Y axis values are all between -1 and 1 as can be seen the command line for the most part but in the plot, y appears to be between 0-800.
Im very new to R, I appreciate any help I can get.
Thank you!
Upvotes: 1
Views: 767
Reputation: 55350
I'm not sure how you loaded the data in, but I am guessing that your values where assumed to be strings and converted to factors.
Regardless of how it happened, what is causing your issue is that your column is a factor
. The giveaway is the final line of output: "804 Levels: ..... "
. Anytime you see that "XXX Levels: ..." statement, you know your data is being stored as factors.
To convert to numbers, first convert to strings, then use as.numeric:
`mseries[, 2] <- as.numeric(as.character(mseries[, 2]))`
# then plot again
Factors in R are stored as integers with a mapping from each integer to a string. So what you are seeing in your Y-axis is the underlying numeric representation. Incidentally, this is also the reason that you first need to convert to string; if you convert a factor to numeric, the number you will receive is the underlying integer value of the factor mapping.
While this may appear confusing for the context in question, for appropriate usage this is extremely practical. For example, for a variable indicating Male / Female.
Upvotes: 1