holgerbrandl / kravis

A {K}otlin g{ra}mmar for data {vis}ualization
BSD 2-Clause "Simplified" License
183 stars 12 forks source link

Missing value where TRUE/FALSE needed #17

Open breandan opened 5 years ago

breandan commented 5 years ago

Encountered this error when plotting with geomLine:

Exception in thread "main" Script:
library(ggplot2)
library(dplyr)
library(readr)
library(scales)
library(forcats)

data01 = read_tsv("/tmp/.txt9217350101246720089.tmp")

set.seed(2009)

gg = ggplot(mapping=aes(x=`x`,y=`y`,color=`Function`), data=data01) + 
    geom_line(stat='identity', position=position_identity(), na.rm=FALSE, inherit.aes=TRUE, size=1.0) + 
    ggtitle("Derivatives of y=(x^(x))")

ggsave(filename="/home/breandan/IdeaProjects/kotlingrad/src/main/resources/plot.png", plot=gg)

Attaching package: ‘dplyr’

The following objects are masked from ‘package:stats’:

    filter, lag

The following objects are masked from ‘package:base’:

    intersect, setdiff, setequal, union

Attaching package: ‘scales’

The following object is masked from ‘package:readr’:

    col_factor

Parsed with column specification:
cols(
  x = col_double(),
  y = col_double(),
  Function = col_character()
)
Saving 7 x 7 in image
Error in if (score > best$score && (!only.loose || (lmin <= dmin && lmax >=  : 
  missing value where TRUE/FALSE needed
Calls: ggsave ... f -> <Anonymous> -> f -> <Anonymous> -> <Anonymous>
Execution halted
    at kravis.render.LocalR.render$kravis(LocalR.kt:23)
    at kravis.GGPlot.save(GGPlot2.kt:164)
    at kravis.GGPlot.save$default(GGPlot2.kt:162)
    at edu.umontreal.kotlingrad.samples.TestPlotKt.main(TestPlot.kt:46)

Code follows:

    val xs = 0.0..5.0 step 0.09
    val ys = (xs.map { listOf(it, y(it), "y") }
            + xs.map { listOf(it, dy_dx(it), "dy/dx") }
            + xs.map { listOf(it, `d²y_dx²`(it), "d²y/x²") }
            + xs.map { listOf(it, `d³y_dx³`(it), "d³y/dx³") }
            + xs.map { listOf(it, `d⁴y_dx⁴`(it), "d⁴y/dx⁴") }
            + xs.map { listOf(it, `d⁵y_dx⁵`(it), "d⁵y/dx⁵") }
      ).flatten()

    dataFrameOf("x", "y", "Function")(ys)
      .plot(x = "x", y = "y", color = "Function")
      .geomLine(size = 1.0)
      .title("Derivatives of y=$y")
      .save(File("src/main/resources/plot.png"))
holgerbrandl commented 3 years ago

I know it's been a while. I've simplified the example to get rid of the differentiation. But then it seems to work fine.

image

holgerbrandl commented 3 years ago

Please also see started test in referenced commit