2017-09-12 7 views
0

변수 "my.data $ V2"(y 축)와 날짜 "my.data $ V3"(x 축)로 구성된 두 개의 데이터 프레임 열을 플롯해야합니다)는 문자열입니다. 기본 플롯과 ggplot 접근법을 사용해 보았지만 작동시키지 못했습니다.R - 플롯 값 대 문자 날짜

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() 

Here 데이터 세트를 찾을 수 있습니다.

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

는 별개의 대답에 솔루션을 추가 + 제목에 해결 추가하지 마십시오, 우리는 해결책이 당신을 위해 일을 나타 내기 허용 대답이있다. –

답변

1

데이터 세트는 문자열 아무것도하지만 구성되어 사용 : 부하 ("data.Rdata")

이 해결을 사용하여 파일을로드합니다. 먼저 변환해야합니다.

> 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() 내부합니다 ($ 연산자없이) 이름으로 변수를 참조해야합니다. 이에 대한 좋은 설명 here를 참조하십시오

ggplot(aes(x = V3, y = V2), data = my.data) + 
    geom_point() 

plot