gpt4 book ai didi

r - R ggplot boxplot错误: Aesthetics must be either length 1 or the same as the data (100): x, y

转载 作者:行者123 更新时间:2023-12-03 07:49:22 30 4
gpt4 key购买 nike

我正在尝试使用数据帧grades_softwaresoftware作为离散变量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")

但是,我得到上述错误:

Aesthetics must be either length 1 or the same as the data (100): x, y



我也不知道将 breaks = seqlimits放入代码中的功能是什么。

最佳答案

您无需为带有ggplot的列指定$

尝试

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

使用 breaks,您可以控制图形的网格线。 Seq创建一系列网格线 seq(from, to, by)。在您的示例中...将网格线每25设置为0到175。另一方面, Limits是长度为2的数字 vector ,提供了比例尺的限制。您的情况是0到175。

关于r - R ggplot boxplot错误: Aesthetics must be either length 1 or the same as the data (100): x, y,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47121561/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com