【问题标题】:Error when plotting using ggplot2: Error in validate_facets(x) : object 'set' not found使用 ggplot2 绘图时出错:validate_facets(x) 中的错误:找不到对象“集”
【发布时间】:2021-11-02 12:06:52
【问题描述】:

我想在 R 中绘制数据,但我不断收到与 facet_grid(-set) 相关的错误,即:Error in validate_facets(x) : object 'set' not found

install.packages('Tmisc')
library(Tmisc)
data(quartet)
View(quartet)

quartet %>%
    group_by(set) %>%
    summarize(mean(x), sd(x), mean(y), sd(y), cor(x,y))
    ggplot(quartet,aes(x,y)) 
        + geom_point() 
        + geom_smooth(method=lm,se=FALSE) 
        + facet_wrap(-set)

> Error in validate_facets(x) : object 'set' not found

【问题讨论】:

  • 即使我不完全确定您的数据看起来如何,您是否尝试过~set 而不是-set
  • 无法重现错误

标签: r facet-wrap


【解决方案1】:

试试这个代码: install.packages('Tmisc') 库(Tmisc) 数据(四重奏) 查看(四重奏)

quartet %>%
    group_by(set) %>%
    summarize(mean(x), sd(x), mean(y), sd(y), cor(x,y)) %>%
    ggplot(quartet,aes(x,y)) 
        + geom_point() 
        + geom_smooth(method=lm,se=FALSE) 
        + facet_wrap(~set)

你必须在 set 前面使用 波浪号而不是破折号,因为 set 是四重奏数据集中的一个独立变量。破折号用于从选择中删除列

【讨论】:

    猜你喜欢
    • 2022-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-21
    • 1970-01-01
    • 2013-11-18
    • 1970-01-01
    相关资源
    最近更新 更多