diff --git a/README.Rmd b/README.Rmd index bf5d8ef..8825425 100644 --- a/README.Rmd +++ b/README.Rmd @@ -34,6 +34,7 @@ print(alig) Plot alignments ```{r define-demo-plot-alignments, eval=TRUE, include = TRUE} library(dtwSat) +library(ggplot2) library(gridExtra) gp1 = plot(alig, type="alignment", attribute="evi", alignment=1, shift=0.5) + ggtitle("Alignment 1") + @@ -48,61 +49,66 @@ grid.arrange(gp1,gp2,nrow=2) Plot path for all classese ```{r define-demo-plot-paths, eval=TRUE, include = TRUE} library(dtwSat) +library(ggplot) library(gridExtra) gp.list = lapply(query.list, function(query){ - alig = twdtw(query, template, weight = "logistic", alpha = 0.1, beta = 50, - alignments = 4, keep = TRUE) + alig = twdtw(query, template, weight = "logistic", alpha = 0.1, + beta = 100, alignments = 4, keep = TRUE) plot(alig, normalize = TRUE, show.dist = TRUE) + - ggtitle(names(query.list)[2]) + theme(axis.title.x=element_blank(), legend.position="none") }) -grid.arrange(gp.list[[1]], - gp.list[[2]], - gp.list[[3]], +grid.arrange(gp.list[[1]] + ggtitle(names(query.list)[1]), + gp.list[[2]] + ggtitle(names(query.list)[2]), + gp.list[[3]] + ggtitle(names(query.list)[3]), nrow=3) ``` - -
    -
  1. Plot classification: - - malig = mtwdtw(query.list, template, weight = "logistic", - alpha = 0.1, beta = 100) +Plot classification +```{r define-demo-plot-classification, eval=TRUE, include = TRUE} +library(dtwSat) +library(ggplot2) +library(gridExtra) +malig = mtwdtw(query.list, template, weight = "logistic", + alpha = 0.1, beta = 100) - gp = plot(x=malig, type="classify", attribute="evi", from=as.Date("2009-09-01"), - to=as.Date("2013-09-01"), by = "6 month", - normalized=TRUE, overlap=.7) - gp - -
  2. -
-![alt text](README-classify.png "Classification plot") - - -
    -
  1. Plot alignments: - df = data.frame(Time=index(template), value=template$evi, variable="Raw") - df = rbind( df, data.frame(Time=index(sy), value=sy$evi, variable="Wavelet filter") ) - gp = ggplot(df, aes(x=Time, y=value, group=variable, colour=variable)) + - geom_line() + - theme(legend.position="bottom") + +gp1 = plot(x=malig, type="classify", from=as.Date("2009-09-01"), + to=as.Date("2013-09-01"), by = "6 month", + normalized=TRUE, overlap=.7) + +gp2 = plot(x=malig, type="classify", attribute = c("evi","ndvi"), + from=as.Date("2009-09-01"), to=as.Date("2013-09-01"), + by = "6 month", normalized=TRUE, overlap=.7) + +grid.arrange(gp1,gp2,nrow=2) +``` + + + +Plot wavelet smoothing +```{r define-demo-plot-smoothing, eval=TRUE, include = TRUE} +library(dtwSat) +library(ggplot2) +library(reshape2) +library(gridExtra) +sy = waveletSmoothing(x=template, frequency=8, wf = "la8", J=1, + boundary = "periodic") +df1 = data.frame(Time=index(template), value=template$evi, variable="Raw") +df1 = rbind(df1, data.frame(Time=index(sy), value=sy$evi, variable="Wavelet filter") ) +gp1 = ggplot(df1, aes(x=Time, y=value, group=variable, colour=variable)) + + geom_line() + + # theme(legend.position="bottom") + ylab("EVI") - gp - -
  2. -
- -![alt text](README-filter.png "Smoothing plot") - -

How to build the package:

-
    -
  1. Clone the project: git clone https//github.com/vwmaus/dtwSat.git.
  2. -
  3. Open Rstudio, go to File - Open Project and pick the file dtwSat.Rproj.
  4. -
  5. Install the required packages install.packages(c("roxygen2", "testthat")).
  6. -
  7. Go to the Build tab in the upper-right panel and press the button Build & Reload. After this the package is ready to use.
  8. -
  9. You can also create a source package: Go to the Build tab, display the menu More and select the option Build Source Package.
  10. -
+ +df2 = melt(data.frame(Time=index(sy), sy), id="Time") +gp2 = ggplot(df2, aes(x=Time, y=value, group=variable, colour=variable)) + + geom_line() + + ylab("Value") +gp2 + +grid.arrange(gp1,gp2,nrow=2) +``` + ```{r, echo = FALSE} diff --git a/README.md b/README.md index 1dc1c6a..b4fcf84 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ Plot alignments ```r library(dtwSat) +library(ggplot2) library(gridExtra) gp1 = plot(alig, type="alignment", attribute="evi", alignment=1, shift=0.5) + ggtitle("Alignment 1") + @@ -71,63 +72,85 @@ Plot path for all classese ```r library(dtwSat) +library(ggplot) +``` + +``` +## Error in library(ggplot): there is no package called 'ggplot' +``` + +```r library(gridExtra) gp.list = lapply(query.list, function(query){ - alig = twdtw(query, template, weight = "logistic", alpha = 0.1, beta = 50, - alignments = 4, keep = TRUE) + alig = twdtw(query, template, weight = "logistic", alpha = 0.1, + beta = 100, alignments = 4, keep = TRUE) plot(alig, normalize = TRUE, show.dist = TRUE) + - ggtitle(names(query.list)[2]) + theme(axis.title.x=element_blank(), legend.position="none") }) -grid.arrange(gp.list[[1]], - gp.list[[2]], - gp.list[[3]], +grid.arrange(gp.list[[1]] + ggtitle(names(query.list)[1]), + gp.list[[2]] + ggtitle(names(query.list)[2]), + gp.list[[3]] + ggtitle(names(query.list)[3]), nrow=3) ``` ![plot of chunk define-demo-plot-paths](figure/define-demo-plot-paths-1.png) +Plot classification -
    -
  1. Plot classification: - - malig = mtwdtw(query.list, template, weight = "logistic", - alpha = 0.1, beta = 100) +```r +library(dtwSat) +library(ggplot2) +library(gridExtra) +malig = mtwdtw(query.list, template, weight = "logistic", + alpha = 0.1, beta = 100) - gp = plot(x=malig, type="classify", attribute="evi", from=as.Date("2009-09-01"), - to=as.Date("2013-09-01"), by = "6 month", - normalized=TRUE, overlap=.7) - gp - -
  2. -
-![alt text](README-classify.png "Classification plot") - - -
    -
  1. Plot alignments: - df = data.frame(Time=index(template), value=template$evi, variable="Raw") - df = rbind( df, data.frame(Time=index(sy), value=sy$evi, variable="Wavelet filter") ) - gp = ggplot(df, aes(x=Time, y=value, group=variable, colour=variable)) + - geom_line() + - theme(legend.position="bottom") + +gp1 = plot(x=malig, type="classify", from=as.Date("2009-09-01"), + to=as.Date("2013-09-01"), by = "6 month", + normalized=TRUE, overlap=.7) + +gp2 = plot(x=malig, type="classify", attribute = c("evi","ndvi"), + from=as.Date("2009-09-01"), to=as.Date("2013-09-01"), + by = "6 month", normalized=TRUE, overlap=.7) + +grid.arrange(gp1,gp2,nrow=2) +``` + +![plot of chunk define-demo-plot-classification](figure/define-demo-plot-classification-1.png) + + + +Plot wavelet smoothing + +```r +library(dtwSat) +library(ggplot2) +library(reshape2) +library(gridExtra) +sy = waveletSmoothing(x=template, frequency=8, wf = "la8", J=1, + boundary = "periodic") +df1 = data.frame(Time=index(template), value=template$evi, variable="Raw") +df1 = rbind(df1, data.frame(Time=index(sy), value=sy$evi, variable="Wavelet filter") ) +gp1 = ggplot(df1, aes(x=Time, y=value, group=variable, colour=variable)) + + geom_line() + + # theme(legend.position="bottom") + ylab("EVI") - gp - -
  2. -
- -![alt text](README-filter.png "Smoothing plot") - -

How to build the package:

-
    -
  1. Clone the project: git clone https//github.com/vwmaus/dtwSat.git.
  2. -
  3. Open Rstudio, go to File - Open Project and pick the file dtwSat.Rproj.
  4. -
  5. Install the required packages install.packages(c("roxygen2", "testthat")).
  6. -
  7. Go to the Build tab in the upper-right panel and press the button Build & Reload. After this the package is ready to use.
  8. -
  9. You can also create a source package: Go to the Build tab, display the menu More and select the option Build Source Package.
  10. -
+ +df2 = melt(data.frame(Time=index(sy), sy), id="Time") +gp2 = ggplot(df2, aes(x=Time, y=value, group=variable, colour=variable)) + + geom_line() + + ylab("Value") +gp2 +``` + +![plot of chunk define-demo-plot-smoothing](figure/define-demo-plot-smoothing-1.png) + +```r +grid.arrange(gp1,gp2,nrow=2) +``` + +![plot of chunk define-demo-plot-smoothing](figure/define-demo-plot-smoothing-2.png) + diff --git a/figure/define-demo-plot-classification-1.png b/figure/define-demo-plot-classification-1.png new file mode 100644 index 0000000..8e3720c Binary files /dev/null and b/figure/define-demo-plot-classification-1.png differ diff --git a/figure/define-demo-plot-paths-1.png b/figure/define-demo-plot-paths-1.png index 89e22f5..dac06d9 100644 Binary files a/figure/define-demo-plot-paths-1.png and b/figure/define-demo-plot-paths-1.png differ diff --git a/figure/define-demo-plot-smoothing-1.png b/figure/define-demo-plot-smoothing-1.png new file mode 100644 index 0000000..2df6a17 Binary files /dev/null and b/figure/define-demo-plot-smoothing-1.png differ diff --git a/figure/define-demo-plot-smoothing-2.png b/figure/define-demo-plot-smoothing-2.png new file mode 100644 index 0000000..b828866 Binary files /dev/null and b/figure/define-demo-plot-smoothing-2.png differ diff --git a/tests/testthat/test_dtwSat.R b/tests/testthat/test_dtwSat.R index aafdfb9..b0899a0 100644 --- a/tests/testthat/test_dtwSat.R +++ b/tests/testthat/test_dtwSat.R @@ -51,6 +51,7 @@ sy = waveletSmoothing(x=template, frequency=8, wf = "la8", J=1, # Plot raw EVI and filtered EVI + df = data.frame(Time=index(template), value=template$evi, variable="Raw") df = rbind( df, data.frame(Time=index(sy), value=sy$evi, variable="Wavelet filter") ) gp = ggplot(df, aes(x=Time, y=value, group=variable, colour=variable)) +