我正在使用 Plotly 和 Shiny在 R 中构建一个交互式时间序列热图。作为此过程的一部分,我将热图值从连续格式重新编码为有序格式 - 所以我有一个热图,其中六种颜色代表特定的计数类别,而这些类别是根据聚合计数值创建的。但是,这会导致使用ggplotly(). 我已经将它追溯到tooltip()Plotly 中呈现交互框的函数。即使我只是向tooltip(). 我正在使用来自约翰霍普金斯 CSSE 存储库. 这是一个简化的热图代码,它也使用辛普森一家的颜色主题ggsci:
#Load packages
library(shiny)
library(plotly)
library(tidyverse)
library(RCurl)
library(ggsci)
#Read example data from Gist
confirmed <- read_csv("https://gist.githubusercontent.com/GeekOnAcid/5638e37c688c257b1c381a15e3fb531a/raw/80ba9704417c61298ca6919343505725b8b162a5/covid_selected_europe_subset.csv")
#Wrap ggplot of time-series heatmap in ggplotly, call "tooltip"
ggplot_ts_heatmap <- confirmed %>%
ggplot(aes(as.factor(date), reorder(`Country/Region`,`cases count`),
fill=cnt.cat, label = `cases count`, label2 = as.factor(date),
text = paste("country:", `Country/Region`))) +
geom_tile(col=1) +
theme_bw(base_line_size = 0, base_rect_size = …Run Code Online (Sandbox Code Playgroud) 我试图用R绘制一个热图.这是可重复的例子:
test <- structure(list(s1 = c(0L, 0L, 1L, 0L, 1L, 1L), s2 = c(1L, 1L,
0L, 1L, 0L, 0L), s3 = c(0L, 0L, 0L, 0L, 0L, 0L), s4 = c(0L, 0L,
0L, 0L, 0L, 0L), s5 = c(0L, 0L, 0L, 0L, 0L, 0L), s6 = c(0L, 0L,
0L, 0L, 0L, 0L)), .Names = c("s1", "s2", "s3", "s4", "s5", "s6"
), row.names = c("5HT2 type receptor mediated signaling pathway",
"5HT3 type receptor mediated signaling pathway", "5-Hydroxytryptamine degredation",
"Alpha adrenergic receptor signaling …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建美国的叶绿体地图,该地图使用分类变量作为州颜色,但我只得到一张空白地图。绘图地图与分类数据兼容吗?如果是这样,语法如何改变?
对于我的数据,我只是上传一个由状态和随机的“好”、“坏”、“好”之一组成的行表。
我可以在下面的代码中更改什么才能使其正常工作?我尝试了一种解决方法,可以稍微改变状态的颜色,但颜色条变得不稳定。(value4 是我的“好”、“坏”、“好”的分类变量)
如果我的问题不清楚或者我的信息不太好,我深表歉意。如果有人有进一步的问题,我可以回答。提前致谢
foo <- brewer.pal(n = 3,
name = "Set1")
df <- mutate(df, test = ntile(x = value4, n = 3))
cw_map <- plot_ly(
data = df,
type = "choropleth",
locations = ~ state,
locationmode = "USA-states",
color = ~ test,
colors = foo[df$test],
z = ~ test
) %>%
layout(geo = list(scope = "usa"))
print(cw_map)
Run Code Online (Sandbox Code Playgroud)