我写了下面的代码。 如何增加颜色栏中值的字体大小,如代码后显示的图中蓝色圆圈所示? 我已经尝试在倒数第二行的代码布局部分进行操作,但它似乎没有用。这在代码中以粗体显示。 感谢您的帮助。
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",
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)
annotations = list(
list(
x = 0.10,
y = 1,
text = "$46/tCO\u2082",
xref = "paper",
yref = "paper",
xanchor = "center",
yanchor = "bottom",
showarrow = FALSE,
font = list(
family = "Arial, sans-serif", # change font family to one that supports subscripts
size = 20,
color = "black",
parse = TRUE
)),
list(
x = 0.37,
y = 1,
text = "$50/tCO\u2082",
xref = "paper",
yref = "paper",
xanchor = "center",
yanchor = "bottom",
showarrow = FALSE,
font = list(
family = "Arial, sans-serif", # change font family to one that supports subscripts
size = 20,
color = "black",
parse = TRUE
)),
list(
x = 0.63,
y = 1,
text = "$56/tCO\u2082",
xref = "paper",
yref = "paper",
xanchor = "center",
yanchor = "bottom",
showarrow = FALSE,
font = list(
family = "Arial, sans-serif", # change font family to one that supports subscripts
size = 20,
color = "black",
parse = TRUE
)),
list(
x = 0.89,
y = 1,
text = "$60/tCO\u2082",
xref = "paper",
yref = "paper",
xanchor = "center",
yanchor = "bottom",
showarrow = FALSE,
font = list(
family = "Arial, sans-serif", # change font family to one that supports subscripts
size = 20,
color = "black",
parse = TRUE
)),
list(
x = 0.5,
y = 1.06,
text = "Benefit-cost analysis at varying CCS cost",
xref = "paper",
yref = "paper",
xanchor = "center",
yanchor = "bottom",
showarrow = FALSE,
font = list(
family = "Arial, sans-serif", # change font family to one that supports subscripts
size = 22,
color = "black"
)),
list(
x = 1.03,
y = 0.99,
text = "B-C Ratio",
xref = "paper",
yref = "paper",
xanchor = "center",
yanchor = "bottom",
showarrow = FALSE,
font = list(
family = "Arial, sans-serif", # change font family to one that supports subscripts
size = 20,
color = "black",
parse = TRUE
)),
list(
x = 0.5,
y = -0.08,
text = "VSL",
xref = "paper",
yref = "paper",
xanchor = "center",
yanchor = "bottom",
showarrow = FALSE,
font = list(
family = "Arial, sans-serif", # change font family to one that supports subscripts
size = 22,
color = "black",
parse = TRUE
)),
list(
x = -0.04,
y = 0.5,
text = "SCC",
xref = "paper",
yref = "paper",
xanchor = "center",
yanchor = "middle",
showarrow = FALSE,
font = list(
family = "Arial, sans-serif", # change font family to one that supports subscripts
size = 22,
color = "black",
parse = TRUE
),
textangle = -90
))
fig <- fig %>% layout(**coloraxis = list(tickfont = list(size = 14)**,
colorscale = 'RdBu'),
annotations = annotations)
fig