Search code examples
rggplot2gghighlight

R ggplot and gghigligt


I am attempting to highlight values in columns 4 and 6 using gghighlight. While I successfully implemented this for column = 4, I have not yet achieved the desired highlighting for both columns simultaneously. see the image

myfraction |> 
 ggplot(aes(pt, n_of_fraction))+
 geom_col(fill = "red")+
 gghighlight(n_of_fraction == 4, n_of_fraction == 6)+
 coord_flip()+
 theme_bw()+
 labs( y = "# Fraction",
    x = "pt",
 scale_y_continuous(expand = c(0, 0)) +
theme(
plot.title = element_markdown(size = 10, face = "bold"), 
#axis.text.y = element_blank(),    # Hide the y-axis text
#axis.ticks.y = element_blank()
)

Solution

  • Try this:

    myfraction |> 
     ggplot(aes(pt, n_of_fraction))+
     geom_col(fill = "red")+
     gghighlight(n_of_fraction == 4 | n_of_fraction == 6)+
     coord_flip()+
     theme_bw()