简体   繁体   中英

Aesthetics must either be length one or the same length

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))

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" with TempDiff and "Gradient Proximal vs. Distal" with Proximal.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:

ggplot(data=Tempdata, aes(x=Measurement.points, y=TempDiff, colour=Proximal.vs.Distal.SD.ext)) + 
  geom_line() +
  geom_errorbar(aes(ymax=ymax, ymin=ymin))

I also fixed some more problems with your original code:

  • the $ issue reported by Roland
  • the fact that you have conflicting calls in your aes
  • the fact you are calling your dataframe inside the first aes

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM