0

Trying to highlight 2 specific points from the next set of data:

Entry,DWSpk,FE
1,1.335703125,36.075
2,1.0821875,45.79413708
3,1.28984375,36.925
5,0.910625,49.125
6,0.8728125,55.9
7,0.84125,56.925
8,0.93875,46.775
9,1.159453125,41.575
10,1.11375,40.45
Rialto,0.89140625,51.875
Savannah,1.33609375,35.275

Try the next code:

p1 <- ggplot(HiBAP1517, aes(FE,DWSpk)) + 
  geom_point(shape=16) + 
  gghighlight(FE==51.875 & FE==35.275) + 
  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

But doesn't seem to work... any idea?

Z.Lin
  • 28,055
  • 6
  • 54
  • 94
Ale
  • 43
  • 6
  • There's no record where `FE==51.875` **AND** `FE==35.275` are true at the same time; you need to use `|` instead of `&`, or, in this case, use `%in%` as answered below. – yutannihilation Dec 23 '18 at 00:51

1 Answers1

1

This should work. I have commented the main edits to your code.

devtools::install_github("yutannihilation/gghighlight")
library(gghighlight)
p1 <- ggplot(HiBAP1517, aes(FE,DWSpk)) + 
  geom_point(shape=16) + 
  gghighlight(FE %in% c(51.875, 35.275)) + # 1st edit
  geom_smooth(method="lm", se = F) +       # 2nd edit
  theme(axis.title.x = element_text(color="black", size=14, face="bold"),
        axis.title.y = element_text(color="black", size=14, face="bold"))
p1
pfinal <- p1 + labs(y = expression("DM spk"^{-1}*"g"),
                    x = expression("FE"*(grainsg^{-1})))
pfinal

enter image description here

paoloeusebi
  • 1,056
  • 8
  • 19
  • In my [problem](https://stackoverflow.com/q/56994202/11339383) I want to get an `ifelse` statement to highlight every "5th" or "nth" element. Can this be used with `gghighlight` or does the argument just accept direct calls like `>` or `%in%`? – Capt.Krusty Jul 18 '19 at 07:10