如何将热图中的标签更改为log10格式?例如c(10^-4.5, 10^-4, 10^-3.5, 10^-3)
我已经尝试过,但没有工作,说NAs生产
myGGplotObject + scale_fill_gradient(name = "log10(meaurement of interest)",low="white", high="red",
breaks = scales::trans_format("log10", scales::math_format(expr = 10^.x)),
labels = scales::trans_format("log10", scales::math_format(expr = 10^.x))
)
下面是我代码的完整示例
# load Library
library(tidyverse)
# create example dataSet
x <- LETTERS[1:20]
y <- paste0("var", seq(1,20))
data <- expand.grid(X=x, Y=y)
length_measurement <- 400
data$Z <- rnorm(400, 0.000025, 0.0005)
#add NA's
addNA <- sample(seq_len(length_measurement), length_measurement/3)
data$Z[addNA] <- NA
#plot Heat map
ggplot(data, aes(Y,X, fill= log10(Z))) +
geom_tile() + scale_fill_gradient(name = "log10(meaurement of interest)",low="white", high="red"#,
#breaks = scales::trans_format("log10", scales::math_format(expr = 10^.x)),
#labels = scales::trans_format("log10", scales::math_format(expr = 10^.x))
)
1条答案
按热度按时间jdgnovmf1#
获取标签的一个选项是使用
scales::label_math
: