Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gghighlight not working with ggtern #135

Open
tash-senior opened this issue Mar 4, 2020 · 10 comments
Open

gghighlight not working with ggtern #135

tash-senior opened this issue Mar 4, 2020 · 10 comments

Comments

@tash-senior
Copy link

It keeps coming up with "Error: Don't know how to add o to a plot" when I try adding gghighlight() to a ternary plot, which has been created using ggtern.

Is this an internal error with the two packages not working together? Or, is it an issue with my code?

@yutannihilation
Copy link
Owner

Could you provide a reprex?

@tash-senior
Copy link
Author

I have subsetted my data (from PSA) as I want to highlight the CoreLocal data only.

CoreLocal <- PSA %>%
subset(Locality == "SNorth" | Locality == "Bk" | Locality == "Tri")

OtherLocal <- PSA %>%
subset(Locality == "BlueL" | Locality == "SSouth" | Locality == "TH" )

ggtern() +
geom_point(data = CoreLocal, aes(x=Mud, y=Gravel, z=Sand, color=Locality, shape=Device)) +
geom_mask() +
theme_showarrows() + custom_percent("Percent") +
gghighlight(CoreLocal)

@yutannihilation
Copy link
Owner

What is PSA? Could you provide a reprex that I can reproduce on my laptop?

@tash-senior
Copy link
Author

Sorry, this is the first time I've created a reproducible code, so let me know if it isn't correct. I just want to use gghighlight() to specify a categorical variable rather than a maximum value.

library(ggtern)
dput(iris)

ggtern(data = iris, aes(x=Sepal.Length, y=Sepal.Width, z=Petal.Length, color=Species)) +
geom_point(size=2) +
geom_mask() +
gghighlight(Species == "setosa")

@yutannihilation
Copy link
Owner

Thanks, really helpful. I could reproduce your example at last! So, this is not that something is wrong with your code. But, I don't understand what's happening here...

library(gghighlight)
#> Loading required package: ggplot2
library(ggtern)
#> Registered S3 methods overwritten by 'ggtern':
#>   method           from   
#>   +.gg             ggplot2
#>   grid.draw.ggplot ggplot2
#>   plot.ggplot      ggplot2
#>   print.ggplot     ggplot2
#> --
#> Remember to cite, run citation(package = 'ggtern') for further info.
#> --
#> 
#> Attaching package: 'ggtern'
#> The following object is masked from 'package:gghighlight':
#> 
#>     aes
#> The following objects are masked from 'package:ggplot2':
#> 
#>     %+%, aes, annotate, calc_element, ggplot, ggplot_build,
#>     ggplot_gtable, ggplotGrob, ggsave, layer_data, theme, theme_bw,
#>     theme_classic, theme_dark, theme_gray, theme_light, theme_linedraw,
#>     theme_minimal, theme_void

ggtern(data = iris, aes(x=Sepal.Length, y=Sepal.Width, z=Petal.Length, color=Species)) +
  geom_point(size=2) +
  geom_mask() +
  gghighlight(Species == "setosa")
#> Error: Don't know how to add o to a plot

Created on 2020-03-13 by the reprex package (v0.3.0)

@tash-senior
Copy link
Author

Yeah, that is the exact issue that came up. I didn't know if it was my syntax for gghighlight(), or if it is just not (and has never been) compatible with ggtern()?

Is there anything you can do about it from your side?

Another option I tried was to subset e.g. 'setosa' and change the shape, colour, and fill. However, this proved to be very difficult as my original dataset needs to specify different shapes for different variables.

@yutannihilation
Copy link
Owner

Is there anything you can do about it from your side?

I want to fix gghighlight to compatible with ggtern, but I'm not sure whether it's technically possible or not, at the moment, sorry.

@tash-senior
Copy link
Author

Okay, thanks for your help anyway!

@tash-senior
Copy link
Author

Just an fyi, I have tried to use gghighlight() for geom_bar and geom_point. It always come up with:

"Error: Don't know how to add o to a plot"

I think it is a bug. My R version is Version 1.2.5001 and computer is macOS Version 10.15.1

This is copied code online, which comes up with the error e.g.

`
library(ggplot2)
library(gghighlight)

d <- data.frame(
idx = c(1, 2, 3, 4, 1, 2, 3, 4),
value = c(10, 11, 12, 13, 4, 8, 16, 32),
cat1 = rep(c("a", "b"), each = 4),
cat2 = rep(rep(c("1-2", "3-4"), each = 2), 2),
stringsAsFactors = FALSE
)

p <- ggplot(d, aes(idx, value, colour = cat1)) +
geom_line() +
facet_wrap(vars(cat2))

p +
gghighlight(max(value) > 10)
#> label_key: cat1

p +
gghighlight(max(value) > 10, calculate_per_facet = TRUE) +
ggtitle("calculate_per_facet = TRUE")`

@yutannihilation
Copy link
Owner

Thanks for the notice, but it's not gghighlight's fault, but ggtern's. In the code below, you can see gghiglight() succeeds before ggtern is loaded, but after library(ggtern), it fails.

I guess ggtern uses some bad magic here. You already noticed or not, ggtern cannot work with the latest version of ggplot2 (I couldn't even install...).

library(ggplot2)
library(gghighlight)

d <- data.frame(
  idx = c(1, 2, 3, 4, 1, 2, 3, 4),
  value = c(10, 11, 12, 13, 4, 8, 16, 32),
  cat1 = rep(c("a", "b"), each = 4),
  cat2 = rep(rep(c("1-2", "3-4"), each = 2), 2),
  stringsAsFactors = FALSE
)

p <- ggplot(d, aes(idx, value, colour = cat1)) +
  geom_line() +
  facet_wrap(vars(cat2))

p +
  gghighlight(max(value) > 10)
#> Warning: The `...` argument of `group_keys()` is deprecated as of dplyr 1.0.0.
#> Please `group_by()` first
#> This warning is displayed once every 8 hours.
#> Call `lifecycle::last_warnings()` to see where this warning was generated.
#> label_key: cat1

library(ggtern, warn.conflicts = FALSE, quietly = TRUE)
#> Registered S3 methods overwritten by 'ggtern':
#>   method           from   
#>   +.gg             ggplot2
#>   grid.draw.ggplot ggplot2
#>   plot.ggplot      ggplot2
#>   print.ggplot     ggplot2
#> --
#> Remember to cite, run citation(package = 'ggtern') for further info.
#> --

p +
  gghighlight(max(value) > 10)
#> Error: Don't know how to add o to a plot

Created on 2020-03-13 by the reprex package (v0.3.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants