EDIT: Stack said my question is very similar to this one (Combine legends for color and shape into a single legend) but that person wanted to join two legends in one and I just want the wrong one to disappear. I added the labs(color="Years", shape = "Years") line, but it still doesn't work. Keeps two legends with one all in black with the correct symbol and the other colorful with the wrong symbol.
#-----------------
I'm creating a geom_point graph and everything was working fine... Until I had to plot my legends.
What I need is the colorful legend, but with the diamond symbol that appears in the all black legend. I've searching for hours and tried to change my code many times, but could not realize what is going on. My code is above the image and I hope someone knows what is happening :c please
dataframe name = correl_temp columns names = ano, correlacao, ajuste and x (x is classified as factor)
ggplot(correl_temp, aes(x = ajuste, y = correlacao, groups = x, label = correlacao)) +
#
geom_point(aes(shape = x, color = x), size = 5) +
geom_text(hjust = 0.5, vjust = -1.2) +
scale_shape_manual(values=c(18,18,18,18,18,18,18,18,18)) +
scale_color_manual(
values = c("#ffd700","#ffb14e","#fa8775",
"#ea5f94","#cd34b5","#9d02d7",
"#0000ff","#072881","#000000"),
labs(color="Years")) +
theme(legend.position="top") +
#
theme_bw() +
scale_y_continuous(n.breaks = 10) +
scale_x_continuous(n.breaks = 10) +
ggtitle("Values of correlation between temperature and mosquitoes captured") +
xlab("Temporal Adjustment (epidemiological weeks)") + ylab("Correlation") +
theme(axis.text = element_text(size = 18, family="Arial"),
axis.title = element_text(size = 18, family = 'Arial'),
plot.title = element_text(size = 20, hjust = 0.5, margin = margin(b = 10)))
I tried removing scale_shape_manual, but had a mess with my symbols and it wasn't solved at all... Tried removing scale_color_manual. The black legend disappeared but then the colors changed... I removed only "labels" from scale_color_manual and it was all the same: black legend with right symbol, colorful legend with wrong symbol...
labs(color="Years", shape = "Years")
- the aesthetics have to share both name and labels.labs()
insidescale_shape_manual()
. Fix the parentheses and make surelabs()
is its own layer and it will work.