0

I'm using R and I've to plot 50 point. My input data are something like these:

Day             Pressure
20/01/2013 13:30:00     980
20/01/2013 20:30:00     978
21/01/2013 13:30:00     985
21/01/2013 20:30:00     991

I've some problems because I can't find the right command to plot the Day vs the Pressure.

pb2q
  • 58,613
  • 19
  • 146
  • 147
user2287830
  • 115
  • 1
  • 4
  • That's because those first columns are character values and need to be converted to Dates or date-times. If this is from an R-object, ...perhaps an xts one? you should post output from `dput(object_name)` – IRTFM Apr 16 '13 at 19:19

3 Answers3

1

This might help you plot the data using ggplot2.

The data I used was as follows:

Day             Pressure
20/01/2013 13:30:00 980
20/01/2013 20:30:00 978
21/01/2013 13:30:00 985
21/01/2013 20:30:00 991

The code is as follows:

library(ggplot2)
data2 <- read.csv("Stack Overflow/timeseries.csv")
data2
data2$Day <- strptime(data2$Day, format="%d/%m/%Y %H:%M:%S")
ggplot(data2, aes(x=Day, y=Pressure))+geom_point()+xlab("Date")

Hope it helps.

Output enter image description here

If you want to use base plot then use the following:

plot(data2$Day,data2$Pressure, xlab="Date",ylab="Pressure")
Jd Baba
  • 5,948
  • 18
  • 62
  • 96
1

Using the zoo package read the data into z and plot it:

Lines <- "Day             Pressure
20/01/2013 13:30:00 980
20/01/2013 20:30:00 978
21/01/2013 13:30:00 985
21/01/2013 20:30:00 991
"

library(zoo)
z <- read.zoo(text = Lines, skip = 1, index = 1:2, tz = "", format = "%d/%m/%Y %H:%M:%S")
plot(z)

enter image description here

G. Grothendieck
  • 254,981
  • 17
  • 203
  • 341
0

You need to convert your "Day" column into Date format for that you need to use as.Date("column") conversion trick. I took the same data as yours

and plotted it. https://i.stack.imgur.com/hWEuc.jpg here..(as i don't have enough reputation points).

library(ggplot2)
library(scales)

date_count<-read.csv("sample_date.csv")
timeline<-as.Date(date_count$Day)
df<-data.frame(timeline,date_count$Pressure)
date_count.tmp<-ggplot(df, aes(x=timeline, y=date_count$Pressure)) + geom_line() 


summary(date_count.tmp)
save(date_count,file="temp_tags_count.rData")
ggsave(file="sample_datecount.pdf")
ggsave(file="sample_datecount.jpeg",dpi=72)

and there you go with your problem solution.

igauravsehrawat
  • 3,696
  • 3
  • 33
  • 46