Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R-绘图值与字符日期_R_Date_Plot_Character - Fatal编程技术网

R-绘图值与字符日期

R-绘图值与字符日期,r,date,plot,character,R,Date,Plot,Character,我想(在单个绘图中)绘图两个数据帧列,它们由变量“my.data$V2”(y轴)和日期“my.data$V3”(x轴)组成,这是一个字符串。我尝试过使用基本图和ggplot方法,但无法使其工作 plot(my.data$V2,my.data$V3,xaxt="n",ylab="Volum") #don't plot the x axis axis.POSIXct(1, at=seq(my.data$V3[1], my.data$V3[2], by="month"), forma

我想(在单个绘图中)绘图两个数据帧列,它们由变量“my.data$V2”(y轴)和日期“my.data$V3”(x轴)组成,这是一个字符串。我尝试过使用基本图和ggplot方法,但无法使其工作

plot(my.data$V2,my.data$V3,xaxt="n",ylab="Volum")          #don't plot the x axis
axis.POSIXct(1, at=seq(my.data$V3[1], my.data$V3[2], by="month"), format="%b") #label the x axis by months


require(ggplot2)
theme_set(theme_bw()) # Change the theme to my preference
ggplot(aes(x = my.data$V3, y = my.data$V2), data = my.data) + geom_point()
您可以找到数据集。使用加载文件 加载(“data.Rdata”)

解决方法:使用

plot(strptime(my.data$V3,"%d/%m/%YT%H:%M:%S",tz="GMT"),my.data$V2, xlab="Time", ylab="Volum")

数据集只包含字符串。你需要先转换它们

> str(my.data)
'data.frame':   17670 obs. of  3 variables:
 $ V1: chr  "236E01VE" "236E01VE" "236E01VE" "236E01VE" ...
 $ V2: chr  "2.571" "2.571" "2.571" "2.571" ...
 $ V3: chr  "13/06/2017T12:55:00" "13/06/2017T13:00:00" "13/06/2017T13:05:00" "13/06/2017T13:10:00" ...

my.data$V2 <- as.numeric(my.data$V2)
my.data$V3 <- as.POSIXct(my.data$V3, format = "%d/%m/%YT%H:%M:%S")

> str(my.data)
'data.frame':   17670 obs. of  3 variables:
 $ V1: chr  "236E01VE" "236E01VE" "236E01VE" "236E01VE" ...
 $ V2: chr  "2.571" "2.571" "2.571" "2.571" ...
 $ V3: POSIXct, format: "2017-06-13 12:55:00" "2017-06-13 13:00:00" "2017-06-13 13:05:00" "2017-06-13 13:10:00" ...

请在不同的答案中添加您的解决方案+不要在标题中添加已解决的问题,我们有已接受的答案,表明解决方案适合您。
ggplot(aes(x = V3, y = V2), data = my.data) + 
  geom_point()