R 绘制详细的热图
我尝试使用以下数据创建热图:R 绘制详细的热图,r,ggplot2,heatmap,ggplotly,R,Ggplot2,Heatmap,Ggplotly,我尝试使用以下数据创建热图: Study Intervention Outcome Study_1 Monetary_Incentive Emission_Reduction Study_2 Govermental_Change Emission_Reduction Study_3 Nudges Renewable_Energy_Usage Study_3 Market_based_i
Study Intervention Outcome
Study_1 Monetary_Incentive Emission_Reduction
Study_2 Govermental_Change Emission_Reduction
Study_3 Nudges Renewable_Energy_Usage
Study_3 Market_based_intervention Renewable_Energy_Usage
Study_4 Market_based_intervention Emission_Reduction
Study_5 Monetary_Incentive Renewable_Energy_Usage
Study_6 Nudges Emission_Reduction
Study_6 Govermental_Change Transport
Study_7 Market_based_intervention Renewable_Energy_Usage
Study_8 Monetary_Incentive Renewable_Energy_Usage
Study_9 Market_based_intervention Emission_Reduction
Study_10 Market_based_intervention Emission_Reduction
Study_10 Monetary_Incentive Renewable_Energy_Usage
Study_11 Market_based_intervention Transport
Study_12 Govermental_Change Transport
Study_13 Monetary_Incentive Emission_Reduction
Study_14 Nudges Transport
我的代码:
input <- read.csv2("Test_dataset.csv")
axis_txt_lim = 60
library(dplyr)
library(ggplot2)
test <- input%>% ggplot2::ggplot() +
ggplot2::geom_count(aes(x = Outcome, y = Intervention),colour = "light
blue", fill ="light blue") +
ggplot2::theme_bw() +
ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 45, hjust = 1),
panel.grid = element_blank(),
text = ggplot2::element_text(size = 14),
axis.title = ggplot2::element_text(size = 16),
title = ggplot2::element_text(size = 18),
legend.position="none") +
ggplot2::xlab(paste0(colnames(data)[2])) +
ggplot2::ylab(paste0(colnames(data)[3])) +
ggplot2::scale_x_discrete(labels = function(x) substr(x, 1, axis_txt_lim))+
ggplot2::scale_y_discrete(labels = function(x) substr(x, 1, axis_txt_lim)) +
ggplot2::ggtitle("Evidence Gap Map", subtitle = paste(colnames(data)[3],
"by", colnames(data)[2]))
test
plotly::ggplotly(test = ggplot2::last_plot())
有什么建议/提示吗?我想做的事情有可能吗?这对
geom\u count
来说很痛苦。下面是使用几何点的一种方法:
library(data.table)
dt0 <- as.data.table(input)
dt <-
dt0[, .(studies = paste0(Study, collapse=","), n = .N), by=c("Outcome","Intervention")]
dt[, n:=as.factor(n)]
gg <- ggplot(dt) +
geom_point(aes(x = Outcome, y = Intervention, size = n, text = studies)) +
scale_size_manual(name = "Nr studies", values = as.numeric(levels(dt$n))) # better legend
ggplotly(gg)
库(data.table)
dt0这对于geom\u计数来说是痛苦的。下面是使用几何点的一种方法:
library(data.table)
dt0 <- as.data.table(input)
dt <-
dt0[, .(studies = paste0(Study, collapse=","), n = .N), by=c("Outcome","Intervention")]
dt[, n:=as.factor(n)]
gg <- ggplot(dt) +
geom_point(aes(x = Outcome, y = Intervention, size = n, text = studies)) +
scale_size_manual(name = "Nr studies", values = as.numeric(levels(dt$n))) # better legend
ggplotly(gg)
库(data.table)
dt0您是否可以尝试input%>%ggplot2::ggplot(aes(text=Study))…
I尝试过,但这不起作用,因为它会干扰geom_count命令。结果是每个点的大小都为1。我错过了这个问题。每个点有几项研究。在我的回答中,我用计数和研究列手动构建表格,然后使用geom_point
和size
美学。你能试试input%>%ggplot2::ggplot(aes(text=Study))…
我做了,但这不起作用,因为它干扰了geom_count命令。结果是每个点的大小都为1。我错过了这个问题。每个点有几项研究。在我的回答中,我用计数和一列手动构建了表格,然后我用geom_point
和size
美学。非常感谢您的帮助,非常感谢:)非常感谢您的帮助,非常感谢:)