Skip to content

annoRect (facet by class) change the original facet order #5

@JJiaSu

Description

@JJiaSu

Hi,
When I try to use annoRect after facet_wrap (~pr.indx), the order of facet is changed, here is my code:

lm.plot <- ggplot(coef_record ) + 
  geom_col(
    aes(x = Beta, y = Variable,
      fill = ifelse(Beta > 0, "#8B4513", "#808080"),  
    )
  ) +
  geom_vline(xintercept = 0, linetype = "dashed", color = "grey40") +
  theme_minimal() +
  theme(
    axis.text.y = element_text(margin = margin(l = 1,unit = 'cm')),
    plot.title = element_text(hjust = 0.5, face = "bold"),
    axis.text = element_text(size = 11, color = "black"),
    panel.grid.major.x = element_line(color = "grey90"),
    panel.grid.major.y = element_blank(),
    # panel.spacing = unit(1,"lines"),
    strip.text = element_text(face = "bold", size = 18, hjust = 0),  
    text = element_text(family = 'Arial',face = "bold", size = 18)
  ) +
  facet_wrap(~pr.idx, nrow  = 1,scales = "free_x",
             labeller = as_labeller(facet_labels),
             drop = FALSE) 
Image

after I do this:

jjAnno::annoRect(object = lm.plot,
         annoPos = 'left',
         aesGroup = T,
         aes_x = 'Beta',
         aes_y = 'Variable',
         aesGroName = 'VariableGroup',
         myFacetGrou = 'Frequency',
         xPosition = c(-1.5,0.2),
         rectWidth = 0.9,
         alpha = 0.3)

Image

Is here anyway to fix this?? Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions