如何使用ggplot2从geom_tile(热图)中删除白线 [英] how to remove white lines from geom_tile (heat map) using ggplot2
问题描述
我无法删除热图中图块之间的白线.下面是我的代码和图片.有人遇到过吗?
t <- ggplot(Drug_heatmap_df_final,
aes(x=reorder(Drug,Total_Deaths), y=Start_Date, fill=Total_Deaths)) +
geom_tile() +
labs(title="Heatmap of Total Deaths per month by Drug", x="Drug", y="Month") +
theme(plot.title = element_text(hjust=.5)) +
scale_y_date(date_breaks="1 year" , labels = date_format("%b-%Y")) +
theme(axis.text.x = element_text(size=13))
plot(t)
我不知道这是否是最优雅的解决方案,但是如果您在aes
中添加color
,然后使用
首先是我的数据用白线显示的样子:
ggplot(mydf, aes(x=grp, y=date, fill=n)) +
geom_tile()
现在,我将颜色设置为与填充和混乱大小相同的对象:
ggplot(mydf, aes(x=grp, y=date, fill=n,color=n)) +
geom_tile(size=0.6)
就像我说的那样,可能不是最优雅的解决方案,并且可能有一种更好,更有效的方法来确定大小值(而不是像我那样反复试验),但总的来说,这似乎可以解决您的问题. /p>
I am having trouble removing the white lines between tiles in my heat map. Below is my code and picture. Has anyone encountered this before?
t <- ggplot(Drug_heatmap_df_final,
aes(x=reorder(Drug,Total_Deaths), y=Start_Date, fill=Total_Deaths)) +
geom_tile() +
labs(title="Heatmap of Total Deaths per month by Drug", x="Drug", y="Month") +
theme(plot.title = element_text(hjust=.5)) +
scale_y_date(date_breaks="1 year" , labels = date_format("%b-%Y")) +
theme(axis.text.x = element_text(size=13))
plot(t)
I don't know if this is the most elegant solution but if you add color
in your aes
and then play with the size in geom_tile
you can get them to overlap and remove the white lines:
First is how my data looks with the white lines:
ggplot(mydf, aes(x=grp, y=date, fill=n)) +
geom_tile()
Now I set my color to the same object as my fill and mess with the size:
ggplot(mydf, aes(x=grp, y=date, fill=n,color=n)) +
geom_tile(size=0.6)
Like I said, probably not the most elegant solution, and there is probably a better, more efficient way to determine the size value (instead of trial and error like I did) but in general this seems to solve your issue.
这篇关于如何使用ggplot2从geom_tile(热图)中删除白线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!