r - R 带圆圈的热图
问题描述
我想在 R 中使用圆圈生成矩阵的热图可视化,以便让圆圈的颜色和直径都提供信息。看起来像这样的东西:
这种绘图在某些计算生物学实验室中被称为“泡泡图”,但我找不到 R 函数/包来做它。
有任何想法吗?谢谢!
解决方案
不确定是否有提供开箱即用的软件包,但仅使用ggplot2
它可以像这样实现:
library(ggplot2)
set.seed(42)
d <- data.frame(
x = rep(paste("Team", LETTERS[1:8]), 4),
y = rep(paste("Task", 1:4), each = 8),
value = runif(32)
)
ggplot(d, aes(x, forcats::fct_rev(y), fill = value, size = value)) +
geom_point(shape = 21, stroke = 0) +
geom_hline(yintercept = seq(.5, 4.5, 1), size = .2) +
scale_x_discrete(position = "top") +
scale_radius(range = c(1, 15)) +
scale_fill_gradient(low = "orange", high = "blue", breaks = c(0, .5, 1), labels = c("Great", "OK", "Bad"), limits = c(0, 1)) +
theme_minimal() +
theme(legend.position = "bottom",
panel.grid.major = element_blank(),
legend.text = element_text(size = 8),
legend.title = element_text(size = 8)) +
guides(size = guide_legend(override.aes = list(fill = NA, color = "black", stroke = .25),
label.position = "bottom",
title.position = "right",
order = 1),
fill = guide_colorbar(ticks.colour = NA, title.position = "top", order = 2)) +
labs(size = "Area = Time Spent", fill = "Score:", x = NULL, y = NULL)
推荐阅读
- dart - Flutter-如何以这种格式发布https?
- java - 无法保存实体可嵌入 ID
- python - 在 Ubuntu 上运行的 Python - TypeError:“Point”类型的对象不是 JSON 可序列化的
- jersey - 无法解决这个问题 UnsatisfiedDependencyException: There was no object available for injection at SystemInjecteeImpl
- android - 更新到 Android Studio 3.2 预览版后 - 项目显示错误找不到方法 create()
- mysql - 在 MySql 选择查询中使用条件
- python - 如何在 pandas 中使用 to_csv 函数时解决分隔符错误
- amazon-web-services - 我们如何使用 AWS 中的云形成在用户池中创建/添加用户?
- python - 使用 iPython 执行 python 脚本时出错
- spring-boot - 在 Spring Boot Gradle 项目中手动添加 3rd 方 jars