2017-09-23 85 views
1

當我創建我的GEOM線圖,我得到這個圖太多的數據點

enter image description here

這裏是我的代碼

ggplot(Moisture_kurokawa, aes(x = Date))+ geom_line(aes(y = W5, colour = "W5"))+ geom_line(aes(y = W7, colour = "W7"))+ geom_line(aes(y = W9, colour = "W9"))+ geom_line(aes(y = W11, colour = "W11")) 

如何得到它平滑任何幫助或看到所有的數據點?

My data file link

回答

2

你應該花一些時間通過一些GGPLOT2教程閱讀,所以你可以讓它做一些工作適合你,特別是如果你做一些數據清理的。

您還需要擁有適合您所需分辨率的適當日期+時間對象。

library(tidyverse) 

Moisture_kurokawa <- read_csv("~/Data/Moisture kurokawa.csv") 

mutate(Moisture_kurokawa, 
     timestamp = lubridate::mdy_hms(sprintf("%s %s", Date, Time))) %>% 
    select(-Date, -Time) %>% 
    gather(W, value, -timestamp) -> moisture_long 

moisture_long 
## # A tibble: 17,645 x 3 
##    timestamp  W value 
##     <dttm> <chr> <dbl> 
## 1 2017-06-24 00:00:00 W5 0.333 
## 2 2017-06-24 00:30:00 W5 0.333 
## 3 2017-06-24 01:00:00 W5 0.334 
## 4 2017-06-24 01:30:00 W5 0.334 
## 5 2017-06-24 02:00:00 W5 0.334 
## 6 2017-06-24 02:30:00 W5 0.334 
## 7 2017-06-24 03:00:00 W5 0.335 
## 8 2017-06-24 03:30:00 W5 0.335 
## 9 2017-06-24 04:00:00 W5 0.335 
## 10 2017-06-24 04:30:00 W5 0.335 
## # ... with 17,635 more rows 

ggplot(moisture_long, aes(timestamp, value, group=W, color=W)) + 
    geom_line() 

enter image description here

有了更好的塑造你的數據,你甚至可以這樣做:

ggplot(moisture_long, aes(timestamp, value, group=W, color=W)) + 
    geom_line() + 
    facet_wrap(~W) 

enter image description here

+0

非常感謝您,先生。我會通過一些教程 –

1
Moisture_kurokawa <- read.table("Moisture kurokawa.csv", header=T, sep=",") 

# Create a datetime object with as.POSIXct 
Moisture_kurokawa$DateTime <- as.POSIXct(
    paste0(Moisture_kurokawa$Date, Moisture_kurokawa$Time), 
    format="%m/%d/%Y %H:%M") 

library(ggplot2)  
ggplot(Moisture_kurokawa, aes(x = DateTime))+ 
    geom_line(aes(y = W5, colour = "W5"))+ 
    geom_line(aes(y = W7, colour = "W7"))+ 
    geom_line(aes(y = W9, colour = "W9"))+ 
    geom_line(aes(y = W11, colour = "W11")) 

enter image description here