I am trying to make a heat map using ggplot and geom_tiles using this code
library(readxl)
library(ggplot2)
library(dplyr)
library(reshape2)
HeLa_half_life_CpG <- read_excel("HeLa_mRNA_stability_chip1_2_combined.xlsx",
sheet = "in_CpG")
melted_CpG <- melt(HeLa_half_life_CpG)
melted_CpG$Genes <- factor(melted_CpG$Genes, levels = unique(melted_CpG$Genes))
pdf("mRNA_stability_CpG.pdf", width = 3, height = 6)
ggplot(melted_CpG, aes(variable, Genes, fill= value)) +
geom_tile()+
xlab("Hours")+
ylab("")+
labs(fill = "% mRNA remaining")+
scale_fill_gradient(low="white",high="blue")+
theme_minimal() +
theme(
text = element_text(size = 14), # Adjust the size as needed
axis.text.y = element_blank(), # Remove y-axis labels
axis.text.x = element_text(size = 14),
legend.position = "none")
dev.off()
and data:
HeLa_half_life_CpG <- structure(
list(
Genes = c(
"G1",
"G2",
"G3",
"G4",
"G5",
"G6",
"G7",
"G8",
"G9",
"G10",
"G11",
"G12",
"G13",
"G14",
"G15",
"G16",
"G17",
"G18",
"G19",
"G20"
),
`0` = c(
100,
100,
100,
100,
100,
100,
100,
100,
100,
100,
100,
100,
100,
100,
100,
100,
100,
100,
100,
100
),
`1` = c(
116.156479707761,
91.0127702731984,
109.73447025453,
86.85808192433,
59.5598276052549,
93.5940148082577,
98.0985395851257,
107.7588571215,
117.531393141036,
90.0590629973177,
108.383548946902,
63.917863771493,
114.108148680618,
121.850793689763,
90.7074115232622,
131.791958956309,
93.4529891706761,
67.1096649073294,
91.4977061761886,
86.3617500276195
),
`2` = c(
96.7597430367575,
80.2076092386504,
99.3294604207776,
99.0190558569627,
39.4558690004756,
49.4282314951013,
77.1264045620156,
99.460774155045,
96.1509176873127,
95.0107882285699,
82.5329765556333,
69.2883553179083,
77.3676845762873,
92.8826806262721,
83.8487800707542,
103.838031673919,
84.9147983928637,
54.3747187092144,
79.1756568571416,
76.9389445509273
),
`4` = c(
105.737036544113,
63.4491092110495,
100.805427725059,
80.2126522696507,
72.7261380578166,
73.3372820751092,
87.5733427132186,
91.0379518564103,
106.094601401991,
93.7441779568787,
98.9266427305014,
60.1007970176505,
113.238459623547,
113.536977434799,
102.44403447203,
84.1038192308167,
90.4763264495684,
67.2430572266142,
99.3241885495501,
80.2126522696507
),
`6` = c(
83.1414918304887,
35.1886581174553,
42.0061328645033,
56.9562322346824,
47.0624266352305,
53.1744300943514,
42.2806827525066,
69.6664507595429,
69.8235275169966,
66.7802812729161,
66.3244186525371,
28.8009528854182,
81.248108118721,
72.5291077149008,
66.1726241174151,
61.1720516419244,
53.0427349921935,
39.7710647621667,
44.6441991796653,
51.9825894198228
),
`8` = c(
66.6264632028956,
48.9905585191921,
52.8504207055527,
47.0404135186142,
32.441664495596,
59.3219007919469,
44.2733303704604,
59.994103633782,
58.8275516186807,
59.9935708643195,
62.3771059829485,
46.842598491202,
77.2048621471892,
68.6596073980867,
62.0572995506867,
46.3846777468947,
56.2083203636403,
45.3269453234242,
46.2646345850238,
58.3949960920727
)
),
row.names = c(NA, -20L),
class = c("tbl_df", "tbl", "data.frame")
)
The heatmap has white space between the tiles of each gene.
enter image description here
I want to remove this space, please help.
This only happens when I export the file as a PDF, but when I run the command R displays the heat map with these white lines between tiles.
Thanks
I tried
geom_tile(width = 1)
but it didn’t work either.
New contributor
Mohd Ahmad is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.