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.

4

3 回答 3

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")
于 2013-04-16T19:27:21.393 回答
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

于 2013-04-16T22:18:47.003 回答
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. http://imgur.com/oyYomZf 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.

于 2013-04-17T09:22:41.000 回答