如何删除此代码中创建的 4 个图例。每个子图一个。它看起来像是一个直接的解决方案,但出于某种原因,我尝试的一切似乎都不起作用?以下是我要修复的代码:
library(plotly)
VSL <- c(79000, 161000, 327000)
SCC <- c(35, 50, 200)
z_data <- list(
fig1 = matrix(
c(0.83, 1.18, 4.69, 0.85, 1.20, 4.71, 0.88, 1.23, 4.74),
nrow = 3, ncol = 3),
fig2 = matrix(
c(0.77, 1.09, 4.31, 0.78, 1.1, 4.33, 0.81, 1.13, 4.36),
nrow = 3, ncol = 3),
fig3 = matrix(
c(0.68, 0.97, 3.85, 0.70, 0.98, 3.87, 0.72, 1.01, 3.89),
nrow = 3, ncol = 3),
fig4 = matrix(
c(0.64, 0.91, 3.60, 0.65, 0.92, 3.61, 0.67, 0.94, 3.63),
nrow = 3, ncol = 3))
# Define the contour properties; `start`/`end` define the min/max
# values of the shown contour range
contours <- list(
showlabels = TRUE,
start = floor(min(unlist(z_data))),
end = ceiling(max(unlist(z_data))),
labelfont = list(size = 20, color = "black"),
size = 0.2)
m <- list(l=100, r=20, b=100, t=100) # l = left; r = right; t = top; b = bottom
# Create a `list` of `plot_ly` objects
lst <- lapply(z_data, function(z) {
plot_ly(
x = ~VSL, y = ~SCC, z = z,
type = "contour",
#coloraxis = "coloraxis", # removed 1
colorbar = list(tickfont = list(size = 20)), # added 2
contours = contours) %>%
layout(
xaxis = list(tickfont = list(size = 20)),
yaxis = list(
tickfont = list(size = 20),
title_font = list(size = 22) # Specify font size for y-axis title
),
margin=m
)
})
# `subplot` accepts a `list` of `plot_ly` objects
fig <- subplot(lst, shareY = TRUE)
fig