[英]R ggplot boxplot Error: Aesthetics must be either length 1 or the same as the data (100): x, y
I am trying to create a boxplot with the data frame grades_software
, software
as a discrete variable X (R/SPSS) and grades
as a continuous variable Y. 我正在尝试使用数据框grades_software
, software
作为离散变量X(R / SPSS)和grades
作为连续变量Y创建箱形图。
I used the following code: 我使用以下代码:
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")
However, I get the error stated above: 但是,我得到上述错误:
Aesthetics must be either length 1 or the same as the data (100): x, y 美学的长度必须为1或与数据(100)相同:x,y
I also don't know what's the function of putting breaks = seq
and limits
in the code. 我也不知道在代码中放置breaks = seq
和limits
的功能是什么。
You don't need to specify $
for the columns with ggplot. 您无需为ggplot的列指定$
。
Try 尝试
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")
With breaks
you control the gridlines of the graph. 使用breaks
您可以控制图形的网格线。 Seq
creates a sequence of gridlines seq(from, to, by)
. Seq
创建一系列网格线seq(from, to, by)
。 In you example... set gridlines from 0 to 175 every 25. Limits
, om the other hand, is a numeric vector of length two providing limits of the scale. 在您的示例中...将网格线每25设置为0到175。另一方面, Limits
是长度为2的数字矢量,提供了比例尺的极限。 In your case, from 0 to 175. 您的情况是0到175。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.