2015-02-23 41 views
-2

我是R的新手。我有关于sap flux的每日时间序列数据,并且想要在R中绘制线图并且想要为日期格式化x轴.my数据文件就是这样的;在R中绘制每日时间序列

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 

请帮助我通过示例R脚本。

+0

这个问题制定得不好。请阅读发布指南以及如何制作一个好的[可重现的示例](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)。 – 2015-02-23 08:45:05

回答

0

你可以试试这个:

# 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") 

这样做是加载了几个包做的情节(当然,如果你没有这些软件包,安装它们),那么它格式化你的约会所以R知道它们是日期(我使用的格式参数与特定的字符串模式匹配),然后它调用ggplot函数来映射数据。

这是否适合您?

+0

非常感谢,其实我是通过这段代码完成的;库(动物园) 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 (y = G1T0,color =“black”,linetype =“dotte”,size =“5”))+ geom_line(aes(y = G1T1,color =“blue”))+ geom_line (“日期”)+ ylab(“Sap Flux”)+ ggtitle(“Group-1_Daily,color =”red“))+ geom_line(aes(y = G1T3,color =”green“))+ xlab Normalized Sap Flux“)+ theme(plot.title = element_text(size = 20,color =”blue“))现在我想要格式化图表Tnx。 – Thilak 2015-02-23 09:28:14