Ale
Ale

Reputation: 43

Highlight 2 specific points ggplot2

I'm trying to highlight 2 specific points with the following code:

p1 <- ggplot(HiBAP1517, aes(FE, DWSpk)) + 
  gghighlight_point(HiBAP1517, aes(FE, DWSpk), value == 51.875) + 
  geom_point(shape=16) + 
  geom_smooth(method=lm, se = F) + 
  theme(axis.title.x = element_text(color="black", size=14, face="bold"), 
        axis.title.y = element_text(color="black", size=14, face="bold"))

pfinal <- p1 + labs(y = expression("DM spk"^{-1}*"g"),
                    x = expression("FE"*(grainsg^{-1})))
pfinal

Getting the following error:

Error in mutate_impl(.data, dots) : Evaluation error: object 'value'not found.

pfinal <- p1 + labs(y = expression("DM spk"^{-1}*"g"), +
                    x = expression("FE"*(grainsg^{-1})))

Error: object 'p1' not found

pfinal 

Error: object 'pfinal' not found

Any ideas what I might be doing wrong? Thanks!

Upvotes: 2

Views: 349

Answers (1)

Erich Neuwirth
Erich Neuwirth

Reputation: 1031

You do not need to specify data and aes in gghighlight, it inherits from ggplot. And my guess is you do not have a variable named value in you dataframe HiBAP151. The condition in highlight needs to refer to your variables. So you probably want gghighlight(FE==51.875) or gghighlight(DWSpk==51.875). Additionally, gghighlight_point is deprecated, you should use gghighlight.

Upvotes: 1

Related Questions