jpquast / ggplate

Create Layout Plots of Biological Culture Plates and Microplates
https://jpquast.github.io/ggplate/
Other
90 stars 6 forks source link

Outlier color in legend limits #12

Closed Theresa-S closed 11 months ago

Theresa-S commented 1 year ago

This package is genius! You saved me so much time :-)

When setting a limit for the color legend, is it possible to assign the "outliers" the same color as the legend limit? In my case the values are not outliers, just a lot higher than the other values, but I am setting a limit so that differences in the "normal" values (especially negative control and positive control) are also visible.

Or is there a command like "outlier.color" or "out.col" which I can use (unfortunately both don`t work)?

Best, Theresa

jpquast commented 11 months ago

Hi @Theresa-S, sorry for the late reply! I think the easiest way to do what you are saying is the code bellow. So basically you can just manually set your "outlier" values to the limit value that you plan to use. You could then technically also leave out the upper limit argument in the plot.

Let me know if this is helps.

Otherwise I could add an additional argument that lets the user specify the outlier colour (similar to here: https://stackoverflow.com/questions/16220812/how-do-i-change-the-na-color-from-gray-to-white-in-a-ggplot-choropleth-map). This is mainly necessary if you want to change it to another colour than the legend limits. But you could also only select one colour and not one for your positive and negative control.

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(tidyr)
library(stringr)
library(ggplate)
#> 📊 Welcome to ggplate version 0.0.1! 📈
#>                             
#> 🖍 Have fun plotting your data! 💻

# Load example data
data("data_continuous_384")

# Limit
upper_limit <- 3

# Create a 384-well plot with adjusted legend limits and outliers
plate_plot(
  data = data_continuous_384,
  position = well,
  value = Value,
  plate_size = 384,
  limits = c(0, 3)
)


# Set the highest values above the limit to limit
outlier_values <- data_continuous_384 %>% 
  mutate(Value = ifelse(Value > upper_limit, upper_limit, Value))

# Create a 384-well plot with adjusted legend limits and outliers in the same colour as the limit
plate_plot(
  data = outlier_values,
  position = well,
  value = Value,
  plate_size = 384,
  limits = c(0, upper_limit)
)

Created on 2023-11-09 with reprex v2.0.2

Theresa-S commented 11 months ago

Thank you so much! No worries, you actually have great timing, I needed the package just this week :-) I'm not sure if you need to add an additional argument. This solution works for me perfectly and I don't know what other people may need...