【发布时间】:2019-07-18 19:40:20
【问题描述】:
我尝试使用以下数据创建热图:
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())
结果:
我想知道是否可以为这些点添加标签/文本,这样如果我将鼠标悬停在这些点上,我不仅可以看到研究的数量,还可以看到研究本身。 我尝试了以下方法,但它并没有真正起作用:
test + geom_text(aes(x = Outcome, y = Intervention, label = Study))
plotly::ggplotly(test = ggplot2::last_plot())
有什么建议/提示吗?我正在尝试做的事情有可能吗?
【问题讨论】:
-
你可以试试
input %>% ggplot2::ggplot(aes(text=Study)) ...... -
我做了,但这不起作用,因为它会干扰 geom_count 命令。结果是每个点的 size=1。
-
我错过了这个问题。每点有几项研究。在我的回答中,我手动构建了带有计数的表格以及用于研究的列,然后我使用
geom_point和size美学。
标签: r ggplot2 heatmap ggplotly