首页 文章

更改热图中值的颜色或删除highcharter R包中的值

提问于
浏览
1

以下是我的数据框

df
  a b c d
1 0 0 0 0
2 0 0 0 1
3 0 0 0 0
4 0 1 0 0

这是生成热图的代码 . 它使用R中的库高级图 .

hchart(as.matrix(df), "heatmap", hcaes(x = variable, y = name, value = value)) %>% hc_colorAxis(stops = color_stops(2, c("yellow","blue")))%>%hc_size(height = 500)

enter image description here

我的问题是,如何更改热图中显示的值/数字的颜色 . 或者,如何从热图中删除值?

1 回答

  • 1

    您可以将代码更改为以下代码:

    加载您的数据:

    mydf <- structure(list(a = c(0L, 0L, 0L, 0L), b = c(0L, 0L, 0L, 1L),        
                           c = c(0L, 0L, 0L, 0L), d = c(0L, 1L, 0L, 0L)), .Names = c("a",      
                                                                                     "b", "c", "d"), row.names = c("1", "2", "3", "4"), class = "data.frame")
    

    然后,生成热图并更改颜色modifyng color_stops 参数:

    hchart(as.matrix(mydf)) %>% 
        hc_colorAxis(stops = color_stops(2, c("white","red"))) %>%
        hc_size(height = 500)
    

    结果如下:

    enter image description here

相关问题