我正在尝试使用此库:https://github.com/swarchal/platetools并修改代码一点,这样我就可以制作交互式平板图片
我所做的是在他们的平板功能中添加以下内容:
plt384_alt<- function (platemap, size = 5, shape = 22)
{
shape <- parse_shape(shape)
ggplotly(ggplot(data = platemap, aes_string(x = "Column", y = "Row")) +
geom_point(data = expand.grid(seq(1, 24), seq(1, 16)),
aes_string(x = "Var1", y = "Var2"), color = "grey90",
fill = "white", shape = shape, size = size - 2, alpha = 0.1) +
geom_point(aes_string(fill = "values"), colour = "gray20",
shape = shape, size = size) + coord_fixed(ratio = (24.5/24)/(16.5/16),
xlim = c(0.5, 24.5), ylim = c(0.5, 16.5)) + scale_y_reverse(breaks = seq(1,16), labels = LETTERS[1:16]) +
scale_x_continuous(position = "top", breaks = seq(1, 24)) + xlab("") + ylab(""))
}
并传递到他们的函数中,在该函数中他们调用
raw_map_alt <- function (data, well, plate = 96, ...)
{
platemap <- plate_map(data, well)
if (plate == 96) {
plt <- plt96(platemap, ...) + theme_bw()
}
else if (plate == 384) {
plt <- plt384_alt(platemap, ...) + theme_bw()
}
else if (plate == 1536L) {
plt <- plt1536(platemap, ...) + theme_bw()
}
else {
stop("Invalid argument for 'plate'. nOption: 96, 384 or 1536",
call. = FALSE)
}
return(plt)
}
但是当我调用这个函数时
raw_map_alt(data = df384$vals,
well = df384$wells,
plate = 384)
我收到以下错误
中的错误,带有(gglayout$yaxis,if(idential(tickmode,"auto"((ticktext else tickvals([[1]]:下标越界此外:警告消息:在L$marker$color[idx]<-中aes2plotly(数据,参数,"填充"([idx]:
中的错误,带有(gglayout$yaxis,if(idential(tickmode,"auto"((ticktext else tickvals([[1]]:下标越界
有人能帮我解释一下发生了什么事吗?
伪数据
wells <- num_to_well(1:384, plate = 384)
vals <- rnorm(length(wells))
df384 <- data.frame(wells, vals)
raw_map_alt(data = df384$vals,
well = df384$wells,
plate = 384)
还发布在platetoil 中完成的parse_shape函数
parse_shape <- function(shape) {
if (is.numeric(shape)) {
return(shape)
} else if (is.character(shape)) {
# R is the worst
# why is it `tolower` and not `to.lower` or `toLower` ????
if (tolower(shape) == "circle") {
return(21L)
} else if (tolower(shape) == "round") {
return(21L)
} else if (tolower(shape) == "square") {
return(22L)
} else {
stop("invalid parameter for shape")
}
} else {stop("invalid parameter for shape")}
}
感谢
在raw_map
函数中,第一行是check_plate_input(well, plate)
。raw_map_alt
函数中缺少此行。这可能是你错误的根源。