nicholasehamilton / ggtern

Extension to ggplot2 for plotting ternary diagrams
www.ggtern.com
55 stars 14 forks source link

aes_string() is missing #25

Open Deleetdk opened 8 years ago

Deleetdk commented 8 years ago

Sometimes one wants to use a function that takes variables as strings and then pastes them into ggplot(). This can easily be done with aes_string(). However, aes_string() is missing from ggtern, so it falls back to using the ggplot2 version. This however means that the z variable is not found.

Example function I was trying to use:

plot_tern = function(df, vars){
  #minimal example
  browser()
  ggtern(df, aes_string(vars[1], vars[2], vars[3])) + geom_point()
}

Calling this gives something like:

Error in value[[3L]](cond) : 
  coord_tern requires the following missing aesthetics: z

Workaround:

One has to declare the name of the z variable explicitly, like this:

plot_tern = function(df, vars, tern_limits){
  ggtern(df, aes_string(vars[1], vars[2], z = vars[3])) + geom_point()
}