R ggplot箱线图错误:长度必须为1或与数据(100)相同:x,y

R ggplot箱线图错误:长度必须为1或与数据(100)相同:x,y,r,ggplot2,error-handling,boxplot,R,Ggplot2,Error Handling,Boxplot,我试图创建一个箱线图,其中数据框grades\u software,software作为离散变量X(R/SPSS),而grades作为连续变量Y 我使用了以下代码: library(ggplot2) ggplot(grades_software, aes(software, grades_software$final_score)) + geom_boxplot(fill = fill, colour = line) + scale_y_continuous(name = "final_s

我试图创建一个箱线图,其中数据框
grades\u software
software
作为离散变量X(R/SPSS),而
grades
作为连续变量Y

我使用了以下代码:

library(ggplot2)
ggplot(grades_software, aes(software, grades_software$final_score)) + 
geom_boxplot(fill = fill, colour = line) +
  scale_y_continuous(name = "final_score",
                     breaks = seq(0, 175, 25),
                     limits=c(0, 175)) +
  scale_x_discrete(name = "software") +
  ggtitle("Distribution of Final Course Scores by Software Used")
但是,我得到了上述错误:

美学必须为长度1或与数据(100)相同:x,y


我也不知道在代码中放置
breaks=seq
limits
的功能是什么。

您不需要为带有ggplot的列指定
$

试一试


使用
中断
可以控制图形的网格线
Seq
创建一系列网格线
Seq(from、to、by)
。在你的例子中。。。每隔25分钟将网格线从0设置为175<代码>限制,从另一方面来说,是一个长度为2的数字向量,提供了刻度的限制。在你的情况下,从0到175

大家好,欢迎来到StackOverflow。请阅读本书,了解如何制作一个很好的R重现性示例。尝试用
aes(软件,等级,软件$final_分数))
替换
aes(软件,最终_分数))
。原因因为已经指定了数据帧,所以我们只需要在
aes
中指定列名。
library(ggplot2)
ggplot(grades_software, aes(software, final_score)) + 
geom_boxplot(fill = fill, colour = line) +
  scale_y_continuous(name = "final_score",
                     breaks = seq(0, 175, 25),
                     limits=c(0, 175)) +
  scale_x_discrete(name = "software") +
  ggtitle("Distribution of Final Course Scores by Software Used")