how to remove white lines from geom_tile (heat map) using ggplot2

坚强是说给别人听的谎言 提交于 2019-12-11 04:48:32

问题


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)


回答1:


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.



来源:https://stackoverflow.com/questions/49179092/how-to-remove-white-lines-from-geom-tile-heat-map-using-ggplot2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!