Swarchal / platetools

An R package for plotting microtitre plates
Other
54 stars 15 forks source link

Function arguments for color and size of missing wells #25

Closed fdchevalier closed 3 years ago

fdchevalier commented 4 years ago

Hello Scott,

First thank you for developing this very helpful package!

While using it, I discovered that missing wells are not very visible on clear background compared to dark background. After inspecting the code, I propose to introduce an argument like na.fill to the plt.() functions. This will allow the user to specify what fill color to use for missing wells. The border color can then specifically be adjusted using the adjustcolor() from the grDevices package (or a na.border argument could also be made).

On the same line, I found that the size of the missing wells too small. Introducing a na.size argument the same way would help. I would also suggest to make it proportionally relative to the the size of the non-missing well.

Here is how the function would look like:

plt96 <- function(platemap, size = 10, shape = 21, na.fill = "white", na.size = 0.6){
    shape <- parse_shape(shape)
    ylim <- c(8.5, 0.5)
    if (is_old_ggplot()) {
        ylim <- rev(ylim)
    }
    ggplot(data = platemap, aes_string(x = "Column", y = "Row")) +
        geom_point(data = expand.grid(seq(1, 12), seq(1, 8)),
                   aes_string(x = "Var1", y = "Var2"),
                   color = adjustcolor(na.fill, offset = -c(0.1,0.1,0.1,0)), fill = na.fill, shape = shape, size = size * na.size, alpha = 0.1) +
        geom_point(aes_string(fill = "values"), colour = "gray20", shape = shape, size = size) +
        coord_fixed(ratio = (13 / 12) / (9 / 8), xlim = c(0.5, 12.5), ylim = ylim) +
        scale_y_reverse(breaks = seq(1, 8), labels = LETTERS[1:8]) +
        scale_x_continuous(position = "top", breaks = seq(1, 12)) +
        xlab("") +
        ylab("")
}

This argument will need to be added to the raw_map() function I guess. If you need help on this, I can implement it.

Thank you,

Fred

Swarchal commented 3 years ago

Hi Fred,

This seems like a good idea. I'll admit I never actually tested it with the clear background.

Swarchal commented 3 years ago

Hi @fdchevalier , you should be able to adjust the size, colour and transparency of missing wells. This is available in the github master branch. It won't be on CRAN yet.

The plot functions now have the additional arguments na_fill, na_alpha and na_size_ratio.

e.g

library(platetools)

df <- data.frame(val = rnorm(96), well = num_to_well(1:96))
df_partial <- dplyr::sample_frac(df, 0.7)

raw_map(
    df_partial$val,
    df_partial$well,
    na_fill = "grey",
    na_size_ratio = 1,
    na_alpha = 1
)

plot

fdchevalier commented 3 years ago

Hi Scott,

Thank you very much for having implemented this! Exactly what I needed. No worries if it is not yet on CRAN. However, do you have any idea when you will release the next version?

Anyway, this can be considered a solved issue.

Fred

Swarchal commented 3 years ago

Glad to help. I will probably submit the current master branch to CRAN in the next week or so.