Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plotIndividualTimeProfile(): error when DataCombined is emtpy #1010

Closed
PavelBal opened this issue Jul 4, 2022 · 3 comments · Fixed by #945
Closed

plotIndividualTimeProfile(): error when DataCombined is emtpy #1010

PavelBal opened this issue Jul 4, 2022 · 3 comments · Fixed by #945

Comments

@PavelBal
Copy link
Member

PavelBal commented Jul 4, 2022

myCombDat <- DataCombined$new()

plotIndividualTimeProfile(myCombDat)

Error in UseMethod("group_by") : 
no applicable method for 'group_by' applied to an object of class "NULL"
8.
dplyr::group_by(., {
{
unitColumn
} ...
7.
dplyr::tally(., name = "unitFrequency")
6.
data %>% dplyr::group_by({
{
unitColumn
} ... at utilities-units.R#693
5.
.extractMostFrequentUnit(data, unitColumn = "xUnit") at utilities-units.R#483
4.
xUnit %||% .extractMostFrequentUnit(data, unitColumn = "xUnit") at utilities-units.R#483
3.
.unitConverter(combinedData, defaultPlotConfiguration$xUnit, 
defaultPlotConfiguration$yUnit) at plot-individual-time-profile.R#41
2.
.plotTimeProfile(dataCombined, defaultPlotConfiguration) at plot-individual-time-profile.R#18
1.
plotIndividualTimeProfile(myCombDat)

Instead, it should produce an empty plot (and, if defined in the plot configuration, title subtitle and so on).

@PavelBal PavelBal changed the title plotObservedVsSimulated(): error when DataCombined is emtpy plotIndividualTimeProfile(): error when DataCombined is emtpy Jul 4, 2022
@IndrajeetPatil
Copy link
Member

Instead, it should produce an empty plot (and, if defined in the plot configuration, title subtitle and so on).

But this is not something tlf can do. It doesn't return an empty plot; it returns NULL instead.

tlf::plotTimeProfile(
  data = data.frame(),
  observedDataMapping = tlf::ObservedDataMapping$new(
    x = "xValues",
    y = "yValues",
    group = "group",
    error = "yErrorValues"
  ),
  plotConfiguration = tlf::TimeProfilePlotConfiguration$new()
)
#> Warning in tlf::plotTimeProfile(data = data.frame(), observedDataMapping =
#> tlf::ObservedDataMapping$new(x = "xValues", : 'data' and 'observedData' are of
#> length 0. Time profile layer was not added.
#> NULL

Created on 2022-07-04 by the reprex package (v2.0.1.9000)

Also, I am not sure if it makes sense to plot anything in such cases.
We should just issue a warning and return a NULL or an empty plot.

library(ggplot2)
ggplot()

Created on 2022-07-04 by the reprex package (v2.0.1.9000)

@IndrajeetPatil
Copy link
Member

I think this is the best solution because we are also being consistent with the underlying tlf function:

library(ospsuite)

myCombDat <- DataCombined$new()
plotIndividualTimeProfile(myCombDat)
#> Warning in .plotTimeProfile(dataCombined, defaultPlotConfiguration): No plot
#> can be created because the entered `DataCombined` object does not contain any
#> datasets.
#> NULL

Created on 2022-07-04 by the reprex package (v2.0.1.9000)

IndrajeetPatil added a commit that referenced this issue Jul 4, 2022
@PavelBal
Copy link
Member Author

PavelBal commented Jul 4, 2022

That sounds reasonable.

IndrajeetPatil added a commit that referenced this issue Jul 18, 2022
* initialize `plotObservedVsSimulated()`

* naming

* preliminary test

* show message only once across groups

* interpolation in edge case

* DRY in setting same properties across plots

* also test custom plot

* for now, only one line

* also test smoother

* update snapshots

* fix tests

* fix tests

* Use `foldDistance` arg from tlf

* Need the latest version

* fix documentation issue

This issue was introduced in #995

* introduce tolerance

* Use unit-dependent thresholds

* linear smoother by default

* add example to aggregated data function

* Update DefaultPlotConfiguration.Rd

* correct fold distance

* deal with linear scale

* update snapshot

* set smoother to NULL

* use long dash

* use expand

* add expand option

* better

* use messages instead

* minor

* catch with tlf

* update snapshots

* pass args to legend config

* update other plots as well

* legend key text should be left-aligned

* address code review comments

* test adding more fold distances work

* Return `NULL` when `DataCombined` is empty

Closes #1010
Closes #1011

* Handle edge case in paired plot

Closes #1012

* remove `smoother` arg

* update snapshots

* fix legend alignment issue

* legendCaption -> legendKeys

* catch up with tlf

* also include residual values

* add error bars to the plot

* comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants