I am trying to plot values and errorbars, a seemingly simple task. As the script is fairly long, I am trying to limit the code in give here to the necessary amount.
I can plot the graph without error bars. However, when trying to add the errorbars I get the message
Error: Aesthetics must either be length one, or the same length as the dataProblems:Tempdata
This is the code I am using. All vectors in the Tempdata data frame are of length 390.
Tempdata <- data.frame (TempDiff, Measurement.points, Room.ext.resc, MelatoninData, Proximal.vs.Distal.SD.ext, ymax, ymin)
p <- ggplot(data=Tempdata,
aes(x = Measurement.points,
y = Tempdata, colour = "Temperature Differences"))
p + geom_line(aes(x=Measurement.points, y = Tempdata$TempDiff, colour = "Gradient Proximal vs. Distal"))+
geom_errorbar(aes(ymax=Tempdata$ymax, ymin=Tempdata$ymin))
Best Answer
The problem is that you have the colour-variables between quotation marks. You should put the variable name at that spot. So, replacing
"Temperature Differences"
withTempDiff
and"Gradient Proximal vs. Distal"
withProximal.vs.Distal.SD.ext
will probably solve your problem.Furthermore: you can can't call for two different
colour
-variables.The improved ggplot code should probably be something like this:
I also fixed some more problems with your original code:
$
issue reported by Rolandaes
aes