简体   繁体   English

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

[英]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_softwaresoftware作为离散变量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 = seqlimits的功能是什么。

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.

相关问题 ggplot2(R):错误消息:'错误:美学长度必须为1或与数据相同(1093):x,y' - ggplot2 (R): Error msg: 'Error: Aesthetics must be either length 1 or the same as the data (1093): x, y' ggplot故障排除:错误:美学长度必须为1或与数据(24)相同:x,y,填充 - ggplot troubleshoot: Error: Aesthetics must be either length 1 or the same as the data (24): x, y, fill 如何避免ggplot错误:“美学的长度必须为1或与数据(84)相同:x,y”? - How to avoid ggplot error: “Aesthetics must be either length 1 or the same as the data (84): x, y”? 错误:美学必须是长度为1或与数据(1)相同:x和y - Error: Aesthetics must be either length 1 or the same as the data (1): x and y 条形图ggplot2-错误:美学必须为长度1或与数据(150)相同:fill,x,y - Bar plot ggplot2 - Error: Aesthetics must be either length 1 or the same as the data (150): fill, x, y GGPlot2:错误:Aesthetics 必须是长度为 1 或与数据相同 (16):x, y, group - GGPlot2: Error: Aesthetics must be either length 1 or the same as the data (16): x, y, group ggplot:错误:美学必须为长度1或与数据(10)相同:x,y,group - ggplot: Error: Aesthetics must be either length 1 or the same as the data (10): x, y, group R中的boxplot,美学必须是长度1或与数据相同的长度 - boxplot in R, aesthetics must be either length 1 or the same length as data R:错误:美学必须是长度1或与数据相同:x - R: Error: Aesthetics must be either length 1 or the same as the data: x 美学必须是长度1或与数据(207)相同:x,y - Aesthetics must be either length 1 or the same as the data (207): x, y
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM