我在热图中删除瓷砖之间的白线时遇到问题。下面是我的代码和图片。有没有人遇到过这个?
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)
答案 0 :(得分:1)
因此,我为同样的问题而苦苦挣扎,无法使犯罪轴(24小时周期)离散。最后,我意识到我每2分钟(一小时的1/30)绘制图块的位置,我的csv数据文件将这些点四舍五入至0.03的间隔,在图块之间留有空隙,因此出现了白线。我只是将excel工作表中的小数位数从2更改为许多,给出了0.03333333的间隔,白线消失了。霍雷! my heatmap before vs after
答案 1 :(得分:0)
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.