美学必须是长度一或长度相同 [英] Aesthetics must either be length one or the same length

查看:180
本文介绍了美学必须是长度一或长度相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图绘制数值和错误条,这是一个看起来很简单的任务。由于脚本相当长,我试图限制在这里给代码所需的代码。



我可以绘制没有错误条形图的图形。但是,当试图添加错误条时,我得到消息



错误:美学必须是长度为1或与dataProblems长度相同: Tempdata



这是我使用的代码。 Tempdata数据帧中的所有矢量长度为390.

  Tempdata < -  data.frame(TempDiff,Measurement.points, Room.xt.resc,MelatoninData,Proximal.vs.Distal.SD.ext,ymax,ymin)
p < - ggplot(data = Tempdata,
aes(x = Measurement.points,$ b $通过= Tempdata,颜色=温差))
p + geom_line(aes(x = Measurement.points,y = Tempdata $ TempDiff,color =Gradient Proximal vs. Distal))+
geom_errorbar (aes(ymax = Tempdata $ ymax,ymin = Tempdata $ ymin))


解决方案<问题是你的引号之间有颜色变量。你应该把变量名称放在那个地方。因此,用 TempDiff 渐变近端与远端替换温差 with Proximal.vs.Distal.SD.ext 可能会解决您的问题。



此外:你不能调用两个不同的 color - 变量。



改进的ggplot代码可能应该是像这样:

  ggplot(data = Tempdata,aes(x = Measurement.points,y = TempDiff,color = Proximal。 )+ 
geom_line()+
geom_errorbar(aes(ymax = ymax,ymin = ymin))

我还修复了一些与原始代码有关的问题:


  • $ Roland报告的问题

  • 您在 aes

  • 您在第一个 aes

$ b $内调用数据框b

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

这篇关于美学必须是长度一或长度相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆