Aesthetics must either be length one, or the same length as the dataProblems

后端 未结 5 569
[愿得一人]
[愿得一人] 2020-12-05 04:09

I would like to make a plot with X values as a subset of the measurement and Y-values as another subset of the measured data.

In the example as below, I have 4 produ

5条回答
  •  一生所求
    2020-12-05 04:56

    I hit this error because I was specifying a label attribute in my geom (geom_text) but was specifying a color in the top level aes:

    df <- read.table('match-stats.tsv', sep='\t')
    library(ggplot2)
    
    # don't do this!
    ggplot(df, aes(x=V6, y=V1, color=V1)) +
      geom_text(angle=45, label=df$V1, size=2)
    

    To fix this, I just moved the label attribute out of the geom and into the top level aes:

    df <- read.table('match-stats.tsv', sep='\t')
    library(ggplot2)
    
    # do this!
    ggplot(df, aes(x=V6, y=V1, color=V1, label=V1)) +
      geom_text(angle=45, size=2)
    

提交回复
热议问题