-2

I'm new to R. I have daily time series data on sap flux and want to plot line graph in R and want to format x-axis for date .my data file is like this;

Date    G1T0    G1T1    G1T2    G1T3
19-Jul-14   0.271081377 0.342416929 0.216215197 0.414495265
20-Jul-14   0.849117059 0.778333568 0.555856888 0.375737302
21-Jul-14   0.742855108 0.756373483 0.536025029 0.255169809
22-Jul-14   0.728504928 0.627172734 0.506561041 0.244863511
23-Jul-14   0.730702865 0.558290192 0.452253842 0.223213402
24-Jul-14   0.62732916  0.461480279 0.377567279 0.180328992
25-Jul-14   0.751401513 0.5404663   0.517567416 0.204342317

Please help me by sample R script.

MrFlick
  • 195,160
  • 17
  • 277
  • 295
Thilak
  • 1
  • 1
  • 4
  • This question is poorly formulated. Please read the posting guide and how to make a good [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – Roman Luštrik Feb 23 '15 at 08:45

1 Answers1

0

You can try this:

# install.packages("ggplot2")
# install.packages("scales")
library(ggplot2)
library(scales)
data$Date <- as.Date(data$Date, format = "%d-%b-%y")
ggplot(data = data, x = Date) +
  geom_line(aes(x = Date, y = G1T0, col = "G1T0")) +
  geom_line(aes(x = Date, y = G1T1, col = "G1T1")) +
  geom_line(aes(x = Date, y = G1T2, col = "G1T2")) +
  geom_line(aes(x = Date, y = G1T3, col = "G1T3")) +
  scale_colour_discrete(name = "Group") +
  labs(y = "Measurement", x = "Date")

What this does is loads a couple of packages to do the plot (obviously, if you don't have those packages, install them), then it formats your date so R knows they're dates (the format argument I used matched your particular string pattern), then it calls the ggplot function to map your data.

Does this work for you?

Roman Luštrik
  • 69,533
  • 24
  • 154
  • 197
goodtimeslim
  • 880
  • 7
  • 13
  • Thanks a lot, Actually I did it by this code;library(zoo) g1 <-read.table("group1-goto.csv",header=T,sep=",") head(g1) summary(g1) g1$Date <- as.Date(g1$Date, '%m/%d/%Y') require(ggplot2) ggplot(data=g1, aes(Date)) + geom_line(aes(y = G1T0, colour = "black",linetype="dotte",size="5")) + geom_line(aes(y = G1T1, colour = "blue"))+ geom_line(aes(y = G1T2, colour = "red"))+ geom_line(aes(y = G1T3, colour = "green"))+ xlab("Date")+ ylab("Sap Flux")+ ggtitle("Group-1_Daily Normalized Sap Flux")+theme(plot.title=element_text(size=20,color="blue")) now I want to format the plot,Tnx. – Thilak Feb 23 '15 at 09:28