I am facing the following problem: I am trying to create a heatmap for my data using ggplot2 and everything worked fine and looks good, except the fact, that in my legend, my colour is divisioned into separate stages corresponding to the column "syn_count". Now I was wondering if there is any way that in the legend, the different stages can be represented as a gradient.
Here is my code:
all <- ggplot(Neu, aes(type, tag, fill = syn_count))+
geom_tile()+
theme(text = element_text(size=8),axis.text.x = element_text(angle = 1, hjust = 1))+
coord_fixed()+
scale_fill_distiller(palette="YlGn")+
labs(title="Inputs of All MeMe-Neurons", x="MeMe-Neuron", y="Inputneuron")+
guides(fill=guide_legend(title="Number of Synapses"))
all
and corresponding my plot: My Plot
I browsed through here and saw solutions with the library scales and scale_fill_gradient2. But since I faced some problem loading the library I was wondering if there is any way using the ggplot2 package without adding any other.
I hope someone here can help my and thanks in advance!
EDIT: Here is an example dataframe:
Tag/syn_count/type
A 24 1
E 500 1
F 310 2
F 67 2
G 266 3
T 80 3
H 270 4
tag(chr) type(chr) syn_count(num)
The problem is on guides(fill=guide_legend(title="Number of Synapses"))
, you should insert in lab()
the fill's title.
Here is an example:
df = tibble(tag = c("A", "B", "C", "D", "E", "F", "G", "H", "I", "J")[runif(100, 1, 10) %>% round()],
syn_count = runif(100, 1, 500) %>% round(),
type = runif(100, 1, 10) %>% round())
ggplot(df, aes(type, tag, fill = syn_count))+
geom_tile()+
theme(text = element_text(size=8),axis.text.x = element_text(angle = 1, hjust = 1))+
coord_fixed()+
scale_fill_distiller(palette="YlGn")+
# add legend title
labs(title="Inputs of All MeMe-Neurons",
x="MeMe-Neuron",
y="Inputneuron",
fill="Number of Synapses") # HERE your legend's title