0

Knitting my File produces the error message down below:

Picture of Error

This is how my File starts:

Start of file

Unfortunately, I couldn't try anything as I have no idea what the error message has to do with the displayed information.

I hope to knit the document to a pdf once this error has been removed.

My code:

library(plotrix) 
p6<-pie3D(rawdata8.2$rawdata8.1, 
          col = hcl.colors(length(data), "Spectral"),
          radius = 1.7, 
          theta = 0.25,  
          shade = 0.5,
          height = 0.3,
          start = pi/1.25, 
          explode = 0.2)
title("Anzahl Ankünfte nach Herkunftsland der Touristen 2020" )
user20650
  • 24,654
  • 5
  • 56
  • 91
  • Hi. Can you edit your question to add your code as text please ... https://meta.stackoverflow.com/questions/285551/why-should-i-not-upload-images-of-code-data-errors – user20650 Jan 07 '23 at 19:28
  • Does the code run in an interactive session e.g. not knitting a doc? – user20650 Jan 07 '23 at 19:31
  • library(plotrix) p6<-pie3D(rawdata8.2$rawdata8.1, col = hcl.colors(length(data), "Spectral"), radius = 1.7, theta = 0.25, shade = 0.5, height = 0.3, start = pi/1.25, explode = 0.2) + title("Anzahl Ankünfte nach Herkunftsland der Touristen 2020" ) – stargazzer101 Jan 07 '23 at 19:31
  • Your're right. It used to work on it's own but it doesn't run anymore in an interactive session – stargazzer101 Jan 07 '23 at 19:35
  • 1
    okay so the error seems to be in `hcl.colors(length(data), "Spectral")`. So step through that. What does `length(data)` give ... is it the value you expect? (ps do this in a fresh R session without loading any previous workspace) – user20650 Jan 07 '23 at 19:37
  • The problem is probably in your 3Dpie and not in the fact that you are knitting to pdf. Please consider checking [pie3D documentation](https://www.rdocumentation.org/packages/plotrix/versions/3.8-2/topics/pie3D). And try to run the code of that particular chunk in your console. – Marja van der Wind Jan 11 '23 at 10:06
  • Check [this example](https://jtr13.github.io/cc19/plotrix-for-complex-visualizations.html#pie3d-example) for instance: did you provide both values and labels for your pie-chart? Does it help to set the radius back to 1? Not sure if it can be higher in user units? Have you defined pi somewhere? Or do you need to call it from a math package? These are some ideas. I hope it helps. This [problem](https://stackoverflow.com/questions/15897087/error-ggplot-error-in-seq-int0-to0-from-by-to-must-be-finite) might also help. – Marja van der Wind Jan 11 '23 at 10:07
  • These comments are late in the discussion, because they were an answer before. Thanks to @BenBolker who upvoted me, I can now change it into comments. – Marja van der Wind Jan 11 '23 at 10:08

2 Answers2

1

The problem is probably in your 3Dpie and not in the fact that you are knitting to pdf. Please consider checking pie3D documentation. And try to run the code of that particular chunk in your console.

Check this example for instance: did you provide both values and labels for your pie-chart? Does it help to set the radius back to 1? Not sure if it can be higher in user units? Have you defined pi somewhere? Or do you need to call it from a math package?

These are some ideas. I hope it helps. This problem might also help.

  • 1
    I've just upvoted this answer so that you will have >50 reputation. Now that you do, I would (paradoxically) like you to re-post this info as a comment rather than an answer, which is it where it belongs ... (I don't think you will lose the reputation by deleting the answer once you've posted the info as a comment ...) – Ben Bolker Jan 07 '23 at 22:56
  • Thank you, indeed I tried to make a comment as I realized that it was meant that way, but indeed couldn't bcs of my reputation. Thanks for helping me out! – Marja van der Wind Jan 11 '23 at 10:03
1

The most obvious problem is that you are probably asking for a palette of length 1:

hcl.colors(1, "Spectral")

Error in seq.int(1, by = -2/(n - 1), length.out = n2) : 'by' must be a finite number

This happens because hcl.colors tries to set up a step size -2/(n-1), which is infinite if n==1.

Guessing beyond this what's going on: unless you have explicitly defined an object called data in your workspace, R will find the built-in function data(): length(data) is 1 (as it seems all functions have length 1 - not quite sure what the logic is here ...)

Also keep in mind that if you have a data frame df, length(df) will give you the number of columns — you would need nrow(df) to get the number of rows ...

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453