plotData: Plot a list data points

Description Usage Arguments Details Value Examples

View source: R/plots.R

Description

Plot a list data points

Usage

1
2
3
4
5
6
7
## S3 method for class 'datalist'
plotData(data, ..., scales = "free", facet = "wrap", transform = NULL)

plotData(data, ...)

## S3 method for class 'data.frame'
plotData(data, ...)

Arguments

data

Named list of data.frames as being used in res, i.e. with columns name, time, value and sigma.

...

Further arguments going to subset.

scales

The scales argument of facet_wrap or facet_grid, i.e. "free", "fixed", "free_x" or "free_y"

facet

Either "wrap" or "grid"

transform

list of transformation for the states, see coordTransform.

Details

The data.frame being plotted has columns time, value, sigma, name and condition.

Value

A plot object of class ggplot.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
    
    ## Observation function
    fn <- eqnvec(
      sine = "1 + sin(6.28*omega*time)",
      cosine = "cos(6.28*omega*time)"
    )
    g <- Y(fn, parameters = "omega")
    
    ## Prediction function for time
    x <- Xt()
    
    ## Parameter transformations to split conditions
    p <- NULL
    for (i in 1:3) {
      p <- p + P(trafo = c(omega = paste0("omega_", i)), condition = paste0("frequency_", i))
    }
    
    ## Evaluate prediction
    times <- seq(0, 1, .01)
    pars <- structure(seq(1, 2, length.out = 3), names = attr(p, "parameters"))
    
    prediction <- (g*x*p)(times, pars)
    
    ## Plotting prediction
    # plot(prediction)
    plotPrediction(prediction)
    plotPrediction(prediction, scales = "fixed")
    plotPrediction(prediction, facet = "grid")
    plotPrediction(prediction, 
                   scales = "fixed",
                   transform = list(sine = "x^2", cosine = "x - 1"))
    
    ## Simulate data
    dataset <- wide2long(prediction)
    dataset <- dataset[seq(1, nrow(dataset), 5),]
    set.seed(1)
    dataset$value <- dataset$value + rnorm(nrow(dataset), 0, .1)
    dataset$sigma <- 0.1
    data <- as.datalist(dataset, split.by = "condition")
    
    ## Plotting data
    # plot(data)
    plot1 <- plotData(data)
     plot1
    ## Plotting data and prediction with subsetting
    # plot(prediction, data)
    plot2 <- plotCombined(prediction, data)
     plot2
    plot3 <- plotCombined(prediction, data, 
                 time <= 0.5 & condition == "frequency_1")
     plot3
    plot4 <- plotCombined(prediction, data, 
                 time <= 0.5 & condition != "frequency_1", 
                 facet = "grid")
     plot4
    plot5 <- plotCombined(prediction, data, aesthetics = list(linetype = "condition"))
     plot5

dMod documentation built on Jan. 27, 2021, 1:07 a.m.