2

I'm trying to manually reorder the y-axis on the plot below to go in order from P1 to P30. I tried to change the levels in the dataframe itself, but I got an error saying:

'Error in eval(substitute(expr), e) : argument is missing, with no default'

Is there another way to reorder the y-axis so that I can avoid this error?

Here is my code for the dataframe and the plot:

#subsetting the data
P_all_indie = 
  P_all_nonames %>%
  group_by(participant, stimuli, condition) %>% 
  summarize(indie_mean = mean(trial_resp.keys))
 
P_speeded_indie = 
  P_all_indie %>% 
  filter(condition == "speeded")

#attempting to order the y-axis variable
P_speeded_indie = within(P_speeded_indie, participant = factor(participant, levels = c('P1', 'P2', 'P3', 'P4', 'P5', 'P6', 'P7', 'P8', 'P9', 'P10', 
                                                            'P11', 'P12', 'P13', 'P14', 'P15', 'P16', 'P17', 'P18', 'P19', 'P20', 
                                                            'P21', 'P22', 'P23', 'P24', 'P25', 'P26', 'P27', 'P28', 'P29', 'P30')))

#got this error:
#'Error in eval(substitute(expr), e) : argument is missing, with no default'


#plotting
ggplot(P_speeded_indie, mapping = aes(x = indie_mean, y = participant)) + 
  geom_density_ridges() +
  ggtitle('Average Individual Responses to Stimuli (Speeded)') +
  ylab('Participant') +
  xlab('Mean Rating per Stimulus') +
  scale_color_discrete(name = "Condition") +
  theme(legend.position = "none")[![enter image description here][1]][1] 

enter image description here

Thomas
  • 51
  • 1
  • 7
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Apr 29 '21 at 02:50

1 Answers1

4

This is an example of where using = for assignment rather than using <- is causing a problem. When you call

P_speeded_indie = within(P_speeded_indie, participant = factor(participant, levels = c('P1', 'P2', 'P3', 'P4', 'P5', 'P6', 'P7', 'P8', 'P9', 'P10', 
                                                            'P11', 'P12', 'P13', 'P14', 'P15', 'P16', 'P17', 'P18', 'P19', 'P20', 
                                                            'P21', 'P22', 'P23', 'P24', 'P25', 'P26', 'P27', 'P28', 'P29', 'P30')))

The R parser assumes you are trying to pass a parameter named participant= to the within function. Hence nothing is getting passed as the expr parameter to within and the error gets thrown. You should either use the <- operator

P_speeded_indie = within(P_speeded_indie, participant <- factor(participant, levels = c('P1', 'P2', 'P3', 'P4', 'P5', 'P6', 'P7', 'P8', 'P9', 'P10', 
                                                            'P11', 'P12', 'P13', 'P14', 'P15', 'P16', 'P17', 'P18', 'P19', 'P20', 
                                                            'P21', 'P22', 'P23', 'P24', 'P25', 'P26', 'P27', 'P28', 'P29', 'P30')))

or wrap your expression in a {} block so it doesn't look like function parameter any more.

P_speeded_indie = within(P_speeded_indie, {participant = factor(participant, levels = c('P1', 'P2', 'P3', 'P4', 'P5', 'P6', 'P7', 'P8', 'P9', 'P10', 
                                                            'P11', 'P12', 'P13', 'P14', 'P15', 'P16', 'P17', 'P18', 'P19', 'P20', 
                                                            'P21', 'P22', 'P23', 'P24', 'P25', 'P26', 'P27', 'P28', 'P29', 'P30'))})
MrFlick
  • 195,160
  • 17
  • 277
  • 295