Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plotting data in R; error: default method not implemented for type 'list'

Tags:

plot

r

ggplot2

I am trying to plot data in ggplot (I tried a CRAN version from github too), but I end up getting an error:

Error in is.finite(x) : default method not implemented for type 'list'

This is the code for the plot:

ggplot(SinglePatient, aes(x = Condition, y = new, fill = Session)) +
  stat_summary(fun.y = mean, geom = "bar", color = 'black', size = 1, position = "dodge") +
  stat_summary(fun.data = mean_se, geom ="errorbar", width = .1, size = 1, position = position_dodge(width=.9))+
  xlab("Condition") + ylab("Reaction time (ms)") +
  scale_y_continuous(expand = c(0,0)) +
  plot_theme

This is an example of data from the data.frame that I am using:


Patient  Session   Stimulus     Trial  Running[Trial]   Block   ACC     Side   Condition  Group  new.RT
7212      post      blue_color.jpg  14  Center2ExpTrialList 2   incorrect   L   Center2Exp  BrainHQ  251    
7212      post      brown_color.jpg 6   Center2ExpTrialList 2   correct     R   Center2Exp  BrainHQ  253
7212      post      blue_color.jpg  19  Center2ExpTrialList 2   correct     L   Center2Exp  BrainHQ  256
7212      post      brown_color.jpg 23  Center2ExpTrialList 12  correct     R   Center2Exp  BrainHQ  261    
7212      post      blue_color.jpg  18  Center2ExpTrialList 2   correct     L   Center2Exp  BrainHQ  267    

Any idea of what I need to change? Thank you so much for your time.

like image 306
Alina Avatar asked Jul 16 '19 18:07

Alina


1 Answers

The solution for when I encountered this issue is to run unlist on the columns you are giving to ggplot. The issue seems to be that ggplot doesn't want to plot things that are lists, and the problem was not solved by downloading the latest version of ggplot either. You may have inadvertently made the data you are giving it a list.

I solved this by simply doing the following:

dataframe$column <- unlist(dataframe$column)

Issue: data is somehow in a list format.

Solution: unlist()

like image 183
Jimmy Avatar answered Sep 19 '22 12:09

Jimmy