error in `compute_aesthetics()`: ! Aesthetics are not valid data columns.

Hello, i'm struggling with an error on R. I'm trying to get a plot that display the significativity like this
Sans titre

My code is here:
stat.test <- datanett %>% t_test(willingness ~ environment, p.adjust.method = "bonferroni")
stat.test
stat.test <- stat.test %>%
add_xy_position(fun="mean",x="environment")

g2 <- datanett %>%
ggplot(aes(x=environment, y=willingness, color=environment)) +
geom_violin(width=1,
alpha=0.2) +
geom_point(stat="summary",
fun="mean",
size=5) +
geom_boxplot(width=0.1,
color="black",
alpha=0.3) +
scale_color_manual(values=met.brewer("Tiepolo"))+
labs(x="Environnement",
y="Willingness to cross")+
theme_minimal() +
theme(legend.position="none",
axis.title = element_text(size = 15),
axis.text = element_text( size = 15))
g2 + stat_pvalue_manual(stat.test, label = "p", tip.length = 0.01)

This print this error

Error:
! Problem while computing aesthetics.
:information_source: Error occurred in the 4th layer.
Caused by error in compute_aesthetics():
! Aesthetics are not valid data columns.
:heavy_multiplication_x: The following aesthetics are invalid:
:heavy_multiplication_x: fill = environment
:information_source: Did you mistype the name of a data column or forget to add
after_stat()?

When I remove fill="environment" in the aes function i don't have anymore this error but i have a ugly plot without color. Do you have clue to help me having my beautiful plot?
Thank you

What packages do you have loaded?

Can you supply us with some sample data? A handy way to supply some sample data is the dput() function. In the case of a large dataset something like dput(head(mydata, 100)) should supply the data we need. Just do dput(mydata) where mydata is your data. Copy the output and paste it here between
```

```

Thank you for your answer, I use these packages: ggplot2, rstatix, tydiverse, dplyr, ggpubr, MetBrewer

I'm not sure they are all usefull for this part.
Here are my data

structure(list(id = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L), levels = c("1", 
"2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", 
"14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", 
"25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", 
"36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", 
"47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", 
"58", "59", "60", "61", "62", "63", "64", "65", "66", "67", "68", 
"69", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", 
"80", "81", "82", "83", "84"), class = "factor"), duree = c(118, 
118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 
118, 118, 118, 118, 118, 118, 118, 118, 118, 118, 150, 150, 150, 
150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 
150, 150, 150, 150, 150, 150, 150, 150, 186, 186, 186, 186, 186, 
186, 186, 186, 186, 186, 186, 186, 186, 186, 186, 186, 186, 186, 
186, 186, 186, 186, 186, 186, 492, 492, 492, 492, 492, 492, 492, 
492, 492, 492, 492, 492, 492, 492, 492, 492, 492, 492, 492, 492, 
492, 492, 492, 492, 204, 204, 204, 204), gender = c("Woman", 
"Woman", "Woman", "Woman", "Woman", "Woman", "Woman", "Woman", 
"Woman", "Woman", "Woman", "Woman", "Woman", "Woman", "Woman", 
"Woman", "Woman", "Woman", "Woman", "Woman", "Woman", "Woman", 
"Woman", "Woman", "Woman", "Woman", "Woman", "Woman", "Woman", 
"Woman", "Woman", "Woman", "Woman", "Woman", "Woman", "Woman", 
"Woman", "Woman", "Woman", "Woman", "Woman", "Woman", "Woman", 
"Woman", "Woman", "Woman", "Woman", "Woman", "Man", "Man", "Man", 
"Man", "Man", "Man", "Man", "Man", "Man", "Man", "Man", "Man", 
"Man", "Man", "Man", "Man", "Man", "Man", "Man", "Man", "Man", 
"Man", "Man", "Man", "Woman", "Woman", "Woman", "Woman", "Woman", 
"Woman", "Woman", "Woman", "Woman", "Woman", "Woman", "Woman", 
"Woman", "Woman", "Woman", "Woman", "Woman", "Woman", "Woman", 
"Woman", "Woman", "Woman", "Woman", "Woman", "Woman", "Woman", 
"Woman", "Woman"), age = c(22, 22, 22, 22, 22, 22, 22, 22, 22, 
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 21, 
21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 
21, 21, 21, 21, 21, 21, 21, 45, 45, 45, 45, 45, 45, 45, 45, 45, 
45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 21, 
21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 
21, 21, 21, 21, 21, 21, 21, 24, 24, 24, 24), eHMI = structure(c(2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 
2L, 2L, 2L), levels = c("Absent", "Can cross", "Can not cross"
), class = "factor"), environment = struct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L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 
1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 
1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 
1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 
1L, 2L, 1L), levels = c("15km/h", "7km/h"), class = "factor"), 
    willingness = c(10, 10, 10, 10, 11, 11, 11, NA, 11, 11, 10, 
    10, 11, 10, 10, 14, 10, 13, 10, 10, 10, 12, 10, 12, 9, 10, 
    9, 9, 8, 8, 8, 8, 8, 9, 10, 8, 9, 9, 9, 8, 10, 9, 9, 9, 10, 
    10, NA, 10, 10, 9, 8, 9, 9, 9, 9, 9, 9, 8, 9, 9, 9, 8, 8, 
    9, 8, 9, 9, 9, 9, 9, 9, 9, 20, 20, 20, 20, 20, 20, 20, 20, 
    0, 0, 0, 0, 0, 0, 0, 0, 14, 6, 20, 20, 18, 4, 20, 20, 17, 
    16, 16, 16), cluster = structure(c(3L, 3L, 3L, 3L, 3L, 3L, 
    3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
    3L, 3L, 3L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
    2L, 2L, 2L, 2L, 2L, 2L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
    4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
    4L, 4L, 4L, 4L), levels = c("1", "2", "3", "4"), class = "factor"), 
    all = c("Can cross-Alone-10m-7km/h", "Can cross-Alone-10m-15km/h", 
    "Can cross-Alone-30m-7km/h", "Can cross-Alone-30m-15km/h", 
    "Can cross-Accompanied-10m-7km/h", "Can cross-Accompanied-10m-15km/h", 
    "Can cross-Accompanied-30m-7km/h", "Can cross-Accompanied-10m-15km/h", 
    "Can not cross-Alone-10m-7km/h", "Can not cross-Alone-10m-7km/h", 
    "Can not cross-Alone-30m-15km/h", "Can not cross-Alone-30m-15km/h", 
    "Can not cross-Accompanied-10m-7km/h", "Can not cross-Accompanied-10m-15km/h", 
    "Can not cross-Accompanied-30m-7km/h", "Can not cross-Accompanied-30m-15km/h", 
    "Absent-Alone-10m-7km/h", "Absent-Alone-10m-15km/h", "Absent-Alone-30m-7km/h", 
    "Absent-Alone-30m-15km/h", "Absent-Accompanied-10m-7km/h", 
    "Absent-Accompanied-10m-15km/h", "Absent-Accompanied-30m-7km/h", 
    "Absent-Accompanied-30m-15km/h", "Can cross-Alone-10m-7km/h", 
    "Can cross-Alone-10m-15km/h", "Can cross-Alone-30m-7km/h", 
    "Can cross-Alone-30m-15km/h", "Can cross-Accompanied-10m-7km/h", 
    "Can cross-Accompanied-10m-15km/h", "Can cross-Accompanied-30m-7km/h", 
    "Can cross-Accompanied-10m-15km/h", "Can not cross-Alone-10m-7km/h", 
    "Can not cross-Alone-10m-7km/h", "Can not cross-Alone-30m-15km/h", 
    "Can not cross-Alone-30m-15km/h", "Can not cross-Accompanied-10m-7km/h", 
    "Can not cross-Accompanied-10m-15km/h", "Can not cross-Accompanied-30m-7km/h", 
    "Can not cross-Accompanied-30m-15km/h", "Absent-Alone-10m-7km/h", 
    "Absent-Alone-10m-15km/h", "Absent-Alone-30m-7km/h", "Absent-Alone-30m-15km/h", 
    "Absent-Accompanied-10m-7km/h", "Absent-Accompanied-10m-15km/h", 
    "Absent-Accompanied-30m-7km/h", "Absent-Accompanied-30m-15km/h", 
    "Can cross-Alone-10m-7km/h", "Can cross-Alone-10m-15km/h", 
    "Can cross-Alone-30m-7km/h", "Can cross-Alone-30m-15km/h", 
    "Can cross-Accompanied-10m-7km/h", "Can cross-Accompanied-10m-15km/h", 
    "Can cross-Accompanied-30m-7km/h", "Can cross-Accompanied-10m-15km/h", 
    "Can not cross-Alone-10m-7km/h", "Can not cross-Alone-10m-7km/h", 
    "Can not cross-Alone-30m-15km/h", "Can not cross-Alone-30m-15km/h", 
    "Can not cross-Accompanied-10m-7km/h", "Can not cross-Accompanied-10m-15km/h", 
    "Can not cross-Accompanied-30m-7km/h", "Can not cross-Accompanied-30m-15km/h", 
    "Absent-Alone-10m-7km/h", "Absent-Alone-10m-15km/h", "Absent-Alone-30m-7km/h", 
    "Absent-Alone-30m-15km/h", "Absent-Accompanied-10m-7km/h", 
    "Absent-Accompanied-10m-15km/h", "Absent-Accompanied-30m-7km/h", 
    "Absent-Accompanied-30m-15km/h", "Can cross-Alone-10m-7km/h", 
    "Can cross-Alone-10m-15km/h", "Can cross-Alone-30m-7km/h", 
    "Can cross-Alone-30m-15km/h", "Can cross-Accompanied-10m-7km/h", 
    "Can cross-Accompanied-10m-15km/h", "Can cross-Accompanied-30m-7km/h", 
    "Can cross-Accompanied-10m-15km/h", "Can not cross-Alone-10m-7km/h", 
    "Can not cross-Alone-10m-7km/h", "Can not cross-Alone-30m-15km/h", 
    "Can not cross-Alone-30m-15km/h", "Can not cross-Accompanied-10m-7km/h", 
    "Can not cross-Accompanied-10m-15km/h", "Can not cross-Accompanied-30m-7km/h", 
    "Can not cross-Accompanied-30m-15km/h", "Absent-Alone-10m-7km/h", 
    "Absent-Alone-10m-15km/h", "Absent-Alone-30m-7km/h", "Absent-Alone-30m-15km/h", 
    "Absent-Accompanied-10m-7km/h", "Absent-Accompanied-10m-15km/h", 
    "Absent-Accompanied-30m-7km/h", "Absent-Accompanied-30m-15km/h", 
    "Can cross-Alone-10m-7km/h", "Can cross-Alone-10m-15km/h", 
    "Can cross-Alone-30m-7km/h", "Can cross-Alone-30m-15km/h"
    ), allcode = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 
    9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 
    21L, 22L, 23L, 24L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 
    11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 
    23L, 24L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 
    13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 
    1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 
    15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 1L, 2L, 
    3L, 4L), levels = c("0000", "0001", "0010", "0011", "0100", 
    "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", 
    "1101", "1110", "1111", "2000", "2001", "2010", "2011", "2100", 
    "2101", "2110", "2111"), class = "factor"), ido = c(1, 2, 
    3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 
    19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 
    34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 
    49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 
    64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 
    79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 
    94, 95, 96, 97, 98, 99, 100)), row.names = c(NA, -100L), class = c("tbl_df", 
"tbl", "data.frame"))

Thanks, the data came through nicely. It is always useful to know what packages are being used. It this case it was clear that you were using an adaption of ggplot2 but I could not remember what it was.

Can you give us your complete code? It is difficult to see what you are doing without the rest of what you are doing.

For some general information on asking questions on the form see FAQ Asking Questions

I don't think I need anything more.

Everything seems to be working fine for me.

library(tidyverse)
library(ggpubr) 
library(rstatix)
library(MetBrewer)

DT <- read.csv('raw.data.csv')

stat.test <- DT %>% t_test(willingness ~ environment, p.adjust.method = "bonferroni")

stat.test <- stat.test %>%
add_xy_position(fun="mean",x="environment")

g2 <- DT %>%
ggplot(aes(x=environment, y=willingness, color=environment)) +
geom_violin(width=1,
alpha=0.2) +
geom_point(stat="summary",
fun="mean",
size=5) +
geom_boxplot(width=0.1,
color="black",
alpha=0.3) +
scale_color_manual(values=met.brewer("Tiepolo"))+
labs(x="Environnement",
y="Willingness to cross")+
theme_minimal() +
theme(legend.position="none",
axis.title = element_text(size = 15),
axis.text = element_text( size = 15))

g2 + stat_pvalue_manual(stat.test, label = "p", tip.length = 0.01)

Sorry for the response time. I put the wrong code. The problem is in the aes function when i add a fill argument.

This gives me an aes function like this:

ggplot(aes(x=environment, y=willingness, color=environment, fill=environment)) 

When i do this, R print me the error message written above.

I think the problem is that the *fill = * command does not work with geom_point() . You can set the colour but not the fill.

It does, but not with the default points. Not sure the OP intended to use anything besides the default points, though.

I was wondering about that after I replied. Does one of the ggXXX packages supply this option?

It's part of ggplot2 itself, but it depends on the shape of the point. Here's a link to the shape section of the vignette on aesthetics:

Thanks. I was looking for a "fill" command a few months ago and missed this completely. I think I just assumed from the help that one could not do it

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.