ggplot2使geom_tile中的缺失值不为空 [英] ggplot2 make missing value in geom_tile not blank

查看:941
本文介绍了ggplot2使geom_tile中的缺失值不为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在R的ggplot2数据可视化包中的 geom_tile()图层中,当单元格不包含数据时,它不会绘制。例如。 http://docs.ggplot2.org/current/geom_tile.html 并搜索缺少值。



我想改变此行为以显示所有图块的最小值。这是可能的,如果是这样的话如何?



额外的上下文:当我使用

  stat_density2d(aes(x = x,y = y,fill = .. density ..),geom =tile,contour = FALSE)

我希望没有密度的地区与密度很小的地区看起来非常相似。就像现在一样,如果说色谱是从蓝色到红色,背景是白色的,那么当瓷砖中没有数据时,它是白色的,并且在瓷砖中存在单个数据点时,就是蓝色。

为数据添加伪计数似乎是可能的,但我如何事先知道如何分配伪计数?并在这种情况下,当有faceting?

解决方案

这个问题也可以通过scale_fill_continuous

  scale_fill_continuous(na.value ='salmon')


In the geom_tile() layer in the ggplot2 data visualization package for R, when a cell contains no data it is not drawn. E.g. http://docs.ggplot2.org/current/geom_tile.html and search for "missing value".

I would like to change this behavior to show the minimum value over all the tiles. Is this possible and if so how?

Additional context: when I use

stat_density2d(aes(x=x,y=y, fill=..density..), geom="tile", contour=FALSE)

I would like the regions with no density to look very similar to the regions with very little density. As it is now, if say the color spectrum is from blue to red and the background is white, then there when there is no data in a tile it is white and when there is a single data point in a tile is blue.

Adding a pseudo count to the data seems possible, but how do I know in advance how to distribute the pseudo-counts? and in the case when there are faceting?

解决方案

This issue can also be fixed by an option in scale_fill_continuous

scale_fill_continuous(na.value = 'salmon')

这篇关于ggplot2使geom_tile中的缺失值不为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆