0

I'm trying to make a boxplot with four categories and two groups in each. The result differs on each run without me changing the code. I have R version 4.1.2 and ggplot2 3.3.5.

The data.frame: The structure of the data.frame

There are no NA's.

The code:

ggplot(temp_df2, aes(x=Category,y=Analysis,fill=Sex)+geom_boxplot()

Some of the results below. The first one is the correct one and the rest are obviously incorrect. I didn't make any changes between runs. There are many more incorrect results, but here are two of them so that you get the idea. The correct result comes around 1/5 to 1/10 of times.

The correct result

The correct result.

Incorrect 1

Incorrect 1.

Incorrect 2

Incorrect 2.

Any idea what's wrong? Any other ways to get the correct result?

Kat
  • 15,669
  • 3
  • 18
  • 51
  • 1
    It looks like you're new to SO; welcome to the community! If you want great answers quickly, it's best to make your question reproducible. This includes sample data like the output from `dput()` or `reprex::reprex()` & any libraries. Check it out: [making R reproducible questions](https://stackoverflow.com/q/5963269). I'm guessing that there is a lot more going on in your script file than this graph. Are you reusing the same object names? Do you modify this data later in the file, without changing the data name? Computers are really literal. `ggplot2` doesn't use randomness here, either. – Kat Sep 12 '22 at 12:57
  • I'm sorry that I can't make this reproducible right now. This whole data is in safe environment where I can't make copy-paste, only screen captures. I hoped that someone'd have had the same problem and could help me forward. I tested this some more and found out that if the above line (ggplot(...)) is saved in a variable, rerunning only that variable on console produces the same effect (=different output). I suspect there's some problem with the memory. If I have time, I'll try to reproduce this in an environment were I can copy-paste. – TapioLahtiharju Sep 19 '22 at 12:55

0 Answers0