0

I am somewhat new to R and I am trying to plot values from real data . x axis is the time and y axis real values but in graph y axis is between 0 and 100, but the real values of y are different.

I need your help.Thank you

Im.ba
  • 11
  • 1
  • `data <- read.table("data.txt") y <- data$V1 t <- c(1:100) plot(t,y) lines(t,y)` this is my code – Im.ba May 24 '16 at 15:15
  • 2
    Please provide us with an [example of your data](http://stackoverflow.com/a/5963610/2005219) – Edward R. Mazurek May 24 '16 at 15:22
  • my data just contain one column : 9,12368 8,90582 8,92218 8,53934 7,99324 7,53952 7,51255 7,1065 6,91431 6,9704 7,92692 7,74947 7,10618 6,50479 5,9741 5,08136 4,32405 3,86809 3,4377 3,54596 3,07406 2,92242 1,67285 1,11221 0,501673 – Im.ba May 25 '16 at 05:40
  • If your data in file have comma as decimal separator then in function `read.table()` add argument `dec=","`. – Didzis Elferts May 26 '16 at 11:28
  • [This a capture of data imported into Rstdio](http://i.stack.imgur.com/ZaAyD.gif) – Im.ba May 26 '16 at 11:59
  • Replace your values with . use gsub function data$V1<- gsub(",",".", data$V1) – Arun kumar mahesh May 26 '16 at 12:12
  • Now it works ,thank you very much – Im.ba May 26 '16 at 12:15
  • Please use the edit link on your question to add additional information. The Post Answer button should be used only for complete answers to the question. - [From Review](/review/low-quality-posts/12487292) – Cristik May 26 '16 at 19:29

3 Answers3

0
y <- c(9.21368, 8.90582, 8.92218, 8.53934, 7.99324, 7.53952, 7.51255, 7.1065, 6.91431,
       6.9704,  7.92692, 7.74947, 7.10618, 6.50479, 5.9741, 5.08136, 4.32405, 3.86809, 
       3.4377, 3.54596, 3.07406, 2.92242, 1.67285, 1.11221, 0.501673)
t <- 1 : length(y)
plot(t, y)

# Length(y) and length(t) must be same.
cuttlefish44
  • 6,586
  • 2
  • 17
  • 34
  • Thank you for your response, like that it works but when I read y values from txt file I can't get the same result , y axis can't dispaly real values ! – Im.ba May 26 '16 at 08:32
0

The y-axis is always like the x axis but in reality is not like that:

the y-axis is always like the x axis but in reality is not like that

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Im.ba
  • 11
  • 1
0
You can view your y-axis values in the plot, by adding text function

    y <- c(9.21368, 8.90582, 8.92218, 8.53934, 7.99324, 7.53952, 7.51255, 7.1065, 6.91431,
           6.9704,  7.92692, 7.74947, 7.10618, 6.50479, 5.9741, 5.08136, 4.32405, 3.86809, 
           3.4377, 3.54596, 3.07406, 2.92242, 1.67285, 1.11221, 0.501673)
    t <- 1: length(y)
    plot(t,y)
    text(t,y,pos=3, cex=0.7)

enter image description here

Arun kumar mahesh
  • 2,289
  • 2
  • 14
  • 22
  • when I read y values from txt file, y-axis can't show real values, it gives me graph like that http://i.stack.imgur.com/Occhh.png – Im.ba May 26 '16 at 11:20