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

plate order in raw_grid #37

Open
konradbuessow opened this issue Dec 13, 2024 · 2 comments
Open

plate order in raw_grid #37

konradbuessow opened this issue Dec 13, 2024 · 2 comments

Comments

@konradbuessow
Copy link

konradbuessow commented Dec 13, 2024

Hello,
a very useful package.
When I make a raw_grid of several plates, the plates are displayed in alphabetical order. I would prefer to show the plates in their original order.

df01 <- data.frame(well = num_to_well(1:96),
                   vals = rnorm(96),
                   plate = "p1")
df02 <- data.frame(well = num_to_well(1:96),
                   vals = rnorm(96),
                   plate = "p2")
df03 <- data.frame(well = num_to_well(1:96),
                   vals = rnorm(96),
                   plate = "p10")
df <- rbind(df01, df02, df03)
raw_grid(data = df$vals,
    well = df$well,
    plate_id = df$plate,
    plate = 96,
ncols = 1)

In this example, the plates will be plotted in the order p1, p10, p2 instead of the orgininal order p1, p2, p10.

unique(df$plate)

[1] "p1" "p2" "p10"

Best Regards,
Konrad

@Swarchal
Copy link
Owner

Hi Konrad,

I don't have access to an R installation right now, so I'll give this a proper look soon, but in the meantime I think there could be a quick fix by modifying your data.

The plate order is determined by ggplot2's facet_wrap() function, which should follow any factor levels. So if you set your factor levels for your plate column, this should fix the issue.

@konradbuessow
Copy link
Author

Hello Swarchal,
Thanks for the fast reply.
I could not solve the problem with factor levels. With facet_wrap, the following code preserves the original order:

df <- mutate(df, plate_id = match(plate, unique(plate)))
ids <- unique(df$plate)
names(ids) <- match(df$plate, unique(df$plate)) %>% unique()
ggplot(df, aes(x=well, y=vals)) + 
  geom_point() + 
  facet_wrap("plate_id", ncol=2, labeller = labeller(plate_id = ids))

This could be a way to preserve the plate order in raw_grid.

Konrad

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