r - 使用对数转换色标时的 ggplotly 鼠标值

标签 r ggplot2 plotly r-plotly

在下面的最小示例中,色标经过对数转换,将鼠标悬停在栅格上方时显示的 z 值也经过对数转换。 这是非常无意义的,我需要用与比例图例相同的单位来表示。

是否可以避免自动进行这种转换?

library(plotly)
library(reshape2)
library(RColorBrewer)

myPalette <- colorRampPalette(brewer.pal(11, "Spectral"))

p <- volcano %>%
  melt() %>% 
  ggplot(aes(Var1, Var2, fill = value)) + geom_tile() +
  scale_fill_gradientn(colours = rev(myPalette(100)), trans="log")

ggplotly(p)

最佳答案

解决方法是这样的,我只是添加了 text = paste("Value:", value) 部分(不受日志影响):

p <- volcano %>%
  melt() %>% 
  ggplot(aes(Var1, Var2, fill = value, text = paste("Value:", value))) + geom_tile() +
  scale_fill_gradientn(colours = rev(myPalette(100)), trans="log")

ggplotly(p, tooltip = c("Var1", "Var2", "text"))

还有 tooltip 来控制悬停时显示的内容。

enter image description here

关于r - 使用对数转换色标时的 ggplotly 鼠标值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54107531/

相关文章:

r - 如何从 R data.frame 获取行

r - 如何在 purrr 中的多个数据集上拟合多个模型?

r - 遍历 FASTA 条目并重命名重复项

r - 按降序排列 facet_wrap 图

python - 对 plotly 在线/离线/袖扣和不同版本感到困惑

python - 是否可以让 Plotly choropleth 使用 ISO 3166-1 alpha-2 国家代码而不是 ISO 3166-1 alpha-3 来映射国家?

r - 仅对 Rnw 文件中已更改的部分运行 knit

r - 使用 ggplot_build () 手动设置后,如何在 ggplot 箱形图中自定义凹口?

r - 不重叠的抖动点

r - 使用ggplot和plotly调整文本位置