- Difficult to specify columns for ggplot
aes()
indirectly.
- What if you have the column name specified in a variable?
- Need this to allow users to select traits in your Shiny app.
input <- list(trait="Sepal.Length")
input$trait
## [1] "Sepal.Length"
Will R would substitute “Sepal.Length” for input$trait
??
iris %>% ggplot(aes(x= input$trait)) + geom_histogram()
## Error in `geom_histogram()`:
## ! Problem while computing stat.
## ℹ Error occurred in the 1st layer.
## Caused by error in `setup_params()`:
## ! `stat_bin()` requires a continuous x aesthetic
## ✖ the x aesthetic is discrete.
## ℹ Perhaps you want `stat="count"`?
aes() Looks for a column called “input$trait” or takes the text inside (“Sepal.Length”) literally and does not know to look for a column named “Sepal.Length”.