jpquast / ggplate

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

Unknown Color code & Error in xy.coords(x, y, setLab = FALSE) : 'list' object cannot be coerced to type 'double #5

Closed MHassanSaeed closed 10 months ago

MHassanSaeed commented 1 year ago

Hi, I tried the package for 96 well plate.

I am getting the following errors:

1. Error: Unknown colour name: c("0.04", "0.04", "0.04", "0.04", "0.04", "0.04", "0.04", "0.03")

It's picking the values from 1st column

2. Error in xy.coords(x, y, setLab = FALSE) : 'list' object cannot be coerced to type 'double'

This is when I specify colors like colour = c("#000004FF", "#51127CFF", "#B63679FF", "#FB8861FF", "#FCFDBFFF").

I have set my columns as numeric.

What could be the reasons?

jpquast commented 1 year ago

Hi @MHassanSaeed, thanks for posting the issue. Can you maybe post a reproducible example of your code? You can use the {reprex} package for that. I am not sure if you use the function correctly or if there is a bug.

MHassanSaeed commented 1 year ago

Hi @jpquast ,

thank you for responding.

Here is reproducible code:

library(ggplate)
#> Warning: package 'ggplate' was built under R version 4.2.2
#> Welcome to ggplate version 0.0.1!
#>                             
#> Have fun plotting your data!
library(reprex)
#> Warning: package 'reprex' was built under R version 4.2.2
ggp1
#> Error in eval(expr, envir, enclos): object 'ggp1' not found
ggp1_df <- data.frame(ggp1)
#> Error in data.frame(ggp1): object 'ggp1' not found
ggp1_df
#> Error in eval(expr, envir, enclos): object 'ggp1_df' not found
ls()
#> character(0)
exists('ggp1_df')
#> [1] FALSE
plate_plot(ggp1_df,
           data = data_continuous_96,
           position = well,
           value = Value,
           label = Value,
           plate_size = 96,
           plate_type = "round"
)
#> Error in plate_plot(ggp1_df, data = data_continuous_96, position = well, : object 'ggp1_df' not found
reprex()
#> ✖ Install the styler package in order to use `style = TRUE`.
#> ℹ Non-interactive session, setting `html_preview = FALSE`.
#> CLIPR_ALLOW has not been set, so clipr will not run interactively
#> Error in switch(where, expr = stringify_expression(x_expr), clipboard = ingest_clipboard(), : EXPR must be a length 1 vector

I tried with and without creating a vector, call the excel file by "readxl" but it didn't work.

File ggp1 is already there, I just run the script in a new file, that's why it showed not found.

jpquast commented 1 year ago

This does not help me much because the data frame is not present for the reprex. You can create code that generates the same data frame for the reprex: dput(ggp1)

Just copy the code that this function generates into the example.

MHassanSaeed commented 1 year ago
install.packages("reprex")
#> Installing package into 'C:/Users/User/AppData/Local/R/win-library/4.2'
#> (as 'lib' is unspecified)
#> package 'reprex' successfully unpacked and MD5 sums checked
#> 
#> The downloaded binary packages are in
#>  C:\Users\User\AppData\Local\Temp\Rtmpcl4ycn\downloaded_packages
library(reprex)
#> Warning: package 'reprex' was built under R version 4.2.2
library(readxl)
library(clipr)
#> Welcome to clipr. See ?write_clip for advisories on writing to the clipboard in R.
read_clip(allow_non_interactive = Sys.getenv("CLIPR_ALLOW", interactive()))
#> Error in error_interactive(): To run write_clip() in non-interactive mode, either call write_clip() with allow_non_interactive = TRUE, or set the environment variable CLIPR_ALLOW=TRUE
ggp1
#> Error in eval(expr, envir, enclos): object 'ggp1' not found
ggp1_df <- data.frame(ggp1)
#> Error in data.frame(ggp1): object 'ggp1' not found
plate_plot(ggp1_df,
           data = data_continuous_96,
           position = well,
           value = Value,
           label = Value,
           plate_size = 96,
           plate_type = "round"
)
#> Error in plate_plot(ggp1_df, data = data_continuous_96, position = well, : could not find function "plate_plot"

reprex()
#> ✖ Install the styler package in order to use `style = TRUE`.
#> ℹ Non-interactive session, setting `html_preview = FALSE`.
#> CLIPR_ALLOW has not been set, so clipr will not run interactively
#> Error in switch(where, expr = stringify_expression(x_expr), clipboard = ingest_clipboard(), : EXPR must be a length 1 vector
dput(ggp1)
#> Error in dput(ggp1): object 'ggp1' not found

` Here is the structure list if you want to see it: structure(list(...1 = c(0.04, 0.04, 0.04, 0.04, 0.04, 0.04, 0.04, 0.03), ...2 = c(0.12, 0.12, 0.12, 0.12, 0.13, 0.12, 0.12, 0.04 ), ...3 = c(0.16, 0.19, 0.18, 0.17, 0.17, 0.17, 0.17, 0.04), ...4 = c(0.18, 0.2, 0.2, 0.18, 0.19, 0.19, 0.19, 0.04), ...5 = c(0.18, 0.21, 0.2, 0.2, 0.19, 0.2, 0.2, 0.04), ...6 = c(0.18, 0.21, 0.2, 0.19, 0.18, 0.19, 0.19, 0.05), ...7 = c(0.19, 0.2, 0.2, 0.19, 0.18, 0.19, 0.19, 0.15), ...8 = c(0.18, 0.2, 0.2, 0.19, 0.19, 0.2, 0.2, 0.19), ...9 = c(0.2, 0.2, 0.19, 0.17, 0.19, 0.2, 0.2, 0.2), ...10 = c(0.2, 0.21, 0.2, 0.19, 0.19, 0.2, 0.2, 0.22), ...11 = c(0.04, 0.04, 0.04, 0.04, 0.04, 0.04, 0.04, 0.04), ...12 = c(0.04, 0.04, 0.04, 0.04, 0.04, 0.04, 0.04, 0.04)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA, -8L))`

jpquast commented 11 months ago

Hi @MHassanSaeed, sorry for the late reply! I just checked and noticed that your data is not in the right format. You can see this when you compare your data to the examples in the documentation.

When you convert it to the long format it works perfectly:

# Load library
library(ggplate)
#> 📊 Welcome to ggplate version 0.0.1! 📈
#>                             
#> 🖍 Have fun plotting your data! 💻
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)

# data
ggp1 <- structure(list(...1 = c(0.04, 0.04, 0.04, 0.04, 0.04, 0.04, 0.04,  0.03), ...2 = c(0.12, 0.12, 0.12, 0.12, 0.13, 0.12, 0.12, 0.04 ), ...3 = c(0.16, 0.19, 0.18, 0.17, 0.17, 0.17, 0.17, 0.04),  ...4 = c(0.18, 0.2, 0.2, 0.18, 0.19, 0.19, 0.19, 0.04), ...5 = c(0.18,  0.21, 0.2, 0.2, 0.19, 0.2, 0.2, 0.04), ...6 = c(0.18, 0.21,  0.2, 0.19, 0.18, 0.19, 0.19, 0.05), ...7 = c(0.19, 0.2, 0.2,  0.19, 0.18, 0.19, 0.19, 0.15), ...8 = c(0.18, 0.2, 0.2, 0.19,  0.19, 0.2, 0.2, 0.19), ...9 = c(0.2, 0.2, 0.19, 0.17, 0.19,  0.2, 0.2, 0.2), ...10 = c(0.2, 0.21, 0.2, 0.19, 0.19, 0.2,  0.2, 0.22), ...11 = c(0.04, 0.04, 0.04, 0.04, 0.04, 0.04,  0.04, 0.04), ...12 = c(0.04, 0.04, 0.04, 0.04, 0.04, 0.04,  0.04, 0.04)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA,  -8L))

# convert data
ggp1_formated <- ggp1 %>% 
  mutate(row = LETTERS[1:n()]) %>% 
  pivot_longer(cols = -row, names_to = "column", values_to = "Value") %>% 
  mutate(column = str_remove(column, pattern = "\\.+")) %>% 
  mutate(well = paste0(row, column)) 

# Plot
plate_plot(ggp1_formated,
           position = well,
           value = Value,
           label = Value,
           plate_size = 96,
           plate_type = "round"
)

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