check_aesthetics() Error - Answers to similar questions dont seem helpful

Hi there,
Have searched for a solution but none have worked or came close to what I am working with. The following code is what I am trying to use. I have plotted nearly the same plot with slightly different variables but can't get this one to work. Thanks!

depth_order <- factor(CRUISE_EN_651_edit_$depth_interval,level= c('5-6', '6-7','7-8', '10-12', '12-14', '14-16', '18-20', '26-27', '29-30', '30-31', '31-32', '32-33', '42-43'))
CRUISE_EN_651_edit_ %>%
pivot_longer(c(clay, silt, very_fine_sand, fine_sand, medium_sand, coarse_sand, very_coarse_sand, total_sand), names_to = "all_sed_type", values_to = "all_percent_in_sample")%>%
ggplot( mapping =aes(x = depth_order , y = all_percent_in_sample))+
geom_bar(stat = "identity")+
facet_wrap(~ all_sed_type, nrow = 3)

#Error in check_aesthetics():
! Aesthetics must be either length 1 or the same as the data (208): x
Backtrace:

The variable depth_order is assigned separately from the data frame CRUISE_EN_651_edit_ and you then reshape the data frame. Should your first line be

CRUISE_EN_651_edit_$depth_order <- factor(CRUISE_EN_651_edit_$depth_interval,level= c('5-6', '6-7','7-8', '10-12', '12-14', '14-16', '18-20', '26-27', '29-30', '30-31', '31-32', '32-33', '42-43'))

Thank you very much! That solved the error.

This topic was automatically closed 7 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.