hadley / ggplot2-book

ggplot2: elegant graphics for data analysis
https://ggplot2-book.org/
1.57k stars 683 forks source link

22 A case study - various problems with the example code #357

Closed AnttiRask closed 1 year ago

AnttiRask commented 1 year ago

22.1 What is a spring? You're using tibble in the first example (and later on under 22.2.3 Constructors and 22.3 Part 2: Adding aesthetics), but since you haven't called the library, it should probably be in this format: tibble::tibble.

22.2.1 Building functionality This bit of code below is causing this error: "Error in eval(ei, envir) : '...' used in an incorrect context"

StatSpring <- ggproto("StatSpring", Stat, 
                      ...
)

This causes more problems later on, but I'm not going to point them out here as I'm sure at least some of them will go away once this problem is fixed.

EDIT: I realized that the above code wasn't supposed to be run, but later on, there is an error, Error: '...' used in an incorrect context that comes from this:

GeomSpring <- ggproto("GeomSpring", GeomPath,
                      ...,
                      setup_data = function(data, params) {
                          cols_to_keep <- setdiff(names(data), c("x", "y", "xend", "yend"))
                          springs <- lapply(seq_len(nrow(data)), function(i) {
                              spring_path <- create_spring(
                                  data$x[i], data$y[i], data$xend[i], data$yend[i], 
                                  diameter = data$diameter[i],
                                  tension = data$tension[i], 
                                  n = params$n
                              )
                              spring_path <- cbind(spring_path, unclass(data[i, cols_to_keep]))
                              spring_path$group <- i
                              spring_path
                          })
                          do.call(rbind, springs)
                      },
                      ...
)
hadley commented 1 year ago

A bunch of fixes have already happened to this chapter and some more are coming. The code in #360 works fine for me.