我正在试图弄清楚如何在热图上显示非数字标签。样本代码:
library(highcharter)
data <- data.frame(
X = rep(c(1:20),3),
Y = c(rep(c("A"), 20), rep(c("B"), 20), rep(c("C"), 20)),
Label = rep(c("V","W","X", "Y", "Z"), 6),
Value = round(rnorm(60))
)
data %>%
hchart(type = "heatmap", hcaes(x = X, y = Y, value = Label, color = Value)) %>%
hc_plotOptions(
series = list(
dataLabels = list(enabled = TRUE
))) %>%
hc_chart(
zoomType = "x"
)
我可以用Plotly创建我想要的东西,但是对于更大的图来说它变得非常慢,我想手动为值/标签分配颜色。
library(plotly)
plot_ly(
x = data$X,
y = data$Y,
z = data$Value,
type = "heatmap",
colors = color_scheme,
# colorbar = list(len=20, limits = c(-100, 100)),
showscale=FALSE
) %>%
add_annotations(
data = data,
x = ~X,
y = ~Y,
text = ~Label,
xref = 'x',
yref = 'y',
showarrow = FALSE,
font=list(color='black'))
1条答案
按热度按时间f0ofjuux1#
选项
dataLabels
用于标记值,您可以在hc_annotations
中使用labels
。首先,创建一个用于注解的数据框:你可以画出你的热图。