-1

My code looks like this right now:

library(ggplot2)
ggplot (y=mean, data=a)+geom_bar(stat="identity")+geom_errorbar(aes(ymin=mean - sd, ymax=mean + sd,width=0.15))

I'm getting the following error:

Error in mean - sd : non-numeric argument to binary operator

These are the libraries that I have loaded:

if(!require(psych)){install.packages("psych")}
if(!require(FSA)){install.packages("FSA")}
if(!require(Rmisc)){install.packages("Rmisc")}
if(!require(ggplot2)){install.packages("ggplot2")}
if(!require(car)){install.packages("car")}
if(!require(multcompView)){install.packages("multcompView")}
if(!require(lsmeans)){install.packages("lsmeans")}
if(!require(rcompanion)){install.packages("rcompanion")}

EDIT:

structure(list(morning.time = c(39.28, 42.32, 45.56, 43.47, 45.1, 
42.44, 49.2, 45.99, 52.48, 49.16, 49.63, 47.4, 48.14, 47.89, 
52.91, 51.56, 49.28, 53.62), morning.pushups = c(32L, 34L, 37L, 
38L, 42L, 45L, 51L, 51L, 52L, 54L, 53L, 52L, 53L, 54L, 57L, 56L, 
54L, 59L), evening.time = c(37.75, 39.58, 42.88, 38.45, 40.72, 
37.12, 39.89, 45.31, 39.73, 42.69, 42.47, 45.47, 43.65, 47.78, 
46.97, 47.75, 46.72, 42.12), evening.pushups = c(30L, 32L, 38L, 
34L, 39L, 37L, 35L, 42L, 39L, 47L, 48L, 48L, 48L, 54L, 52L, 47L, 
49L, 47L)), .Names = c("morning.time", "morning.pushups", "evening.time", 
"evening.pushups"), class = "data.frame", row.names = c(NA, -18L
))
  • 2
    What does your data.frame `a` look like? And having the `y=mean` outside an `aes()` seems suspicious. You need to create a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input data so we can see what's really going on. – MrFlick Nov 30 '16 at 22:15
  • I am so new to this, I don't even know how to do that here. – Chris Evans Nov 30 '16 at 22:28
  • 1
    Click on the link I gave you for examples. – MrFlick Nov 30 '16 at 22:29
  • Okay, edited. Although that seems to make matters more confusing. – Chris Evans Nov 30 '16 at 23:11
  • 1
    You aren't referencing any of those columns in your ggplot command. That's not not ggplot works at all. Do you have a variable named `mean` somewhere else? This doesn't seem like a well formed question at this point. Maybe google for a basic ggplot introduction or tutorial. – MrFlick Nov 30 '16 at 23:17
  • Maybe I should do that. Like I said, i am very new to this. – Chris Evans Dec 01 '16 at 00:28
  • Like @MrFlick said, check out the tutorials and basics. For your example, you will have to calculate statistics outside of ggplot and then plot them. Perhaps working with long data format will be for your. Also check out `tidyr` and its function(s) `gather` and `spread`. In words of Tony the tiger, they're great! – Roman Luštrik Dec 01 '16 at 08:29

1 Answers1

0

You didn't specify where your data is coming from it has no clue what "mean" you are referring to as well as putting aes() aroudn x and y and most likely you will haev to refer to your data as data$mean or data$sd and I recommend having a column called "UCL" and "LCL" so you don't do calculations in the code.

`ggplot (data=YOURDATAFRAMEGOESHERE,aes(y=mean,x=XVARGOESHERE))+
 geom_bar(stat="identity")+
 geom_errorbar(aes(ymin=mean - sd,
                   ymax=mean + sd,width=0.15))`

So any time you see "something rather to binary operator" it simply means something is off with the program recognizing your variables or you forgot a "+" between your geoms

zazu
  • 344
  • 3
  • 9