How to refer to a variable name with spaces?

后端 未结 3 1532
没有蜡笔的小新
没有蜡笔的小新 2020-12-08 07:32

In ggplot2, how do I refer to a variable name with spaces?

Why do qplot() and ggplot() break when used on variable names with

3条回答
  •  情话喂你
    2020-12-08 08:22

    Something similar was asked on ggplot2 mailing list and Mehmet Gültaş linked to this post. Another way of using strings to construct your ggplot call is through the aes_strings function. Note that you still have to put backticks inside the quotes for the thing to work for variables with spaces.

    library(ggplot2)
    
    names(mtcars)[1] <- "em pi dzi"
    
    ggplot(mtcars, aes_string(x = "cyl", y = "`em pi dzi`")) +
      theme_bw() +
      geom_jitter()
    

提交回复
热议问题