ggplot2 aes_string() fails to handle names starting with numbers or containing spaces

前端 未结 4 841
刺人心
刺人心 2020-12-15 08:32

If the column names of a data.frame are started with numbers, or have spaces, aes_string() fails to handle them:

foo=data.frame(\"1         


        
4条回答
  •  执笔经年
    2020-12-15 08:55

    I had similar situation and I used `` to make it understand:

    mydf$ROIs <- row.names(mydf)
    df.long <- melt(mydf)
    colnames(df.long)[3] <- "Methods"
    colnames(df.long)[4] <- "Mean L2 Norm Error"
    variable.name="Variable", na.rm=TRUE)
    ggplot(df.long, aes(ROIs, `Mean L2 Norm Error`, fill=Methods))+  
    geom_bar(stat="identity",position="dodge")+
    theme(axis.text.x=element_text(angle=45,hjust=1,vjust=1))
    

提交回复
热议问题