Hello, I have a subtitle overlay problem in ggplot. The following error message appears.
Scale for 'fill' is already present. Adding another scale for 'fill', which
will replace the existing scale.
I used two overlapping data.frames whose structures follow:
dput(newdf)
structure(list(Col2 = c(2013L, 2013L, 2013L, 2013L, 2013L, 2013L,
2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L,
2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2013L,
2013L, 2013L, 2013L, 2013L, 2013L, 2013L, 2015L, 2015L, 2015L,
2015L, 2015L, 2015L, 2015L, 2015L, 2016L, 2016L, 2016L, 2017L,
2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L,
2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L
), T_Ef = c("Col22", "Col22", "Col22", "Col22", "Col22", "Col22",
"Col22", "Col22", "Col22", "Col23", "Col23", "Col23", "Col23",
"Col23", "Col23", "Col23", "Col23", "Col23", "Col23", "Col26",
"Col26", "Col26", "Col26", "Col26", "Col27", "Col27", "Col27",
"Col27", "Col28", "Col28", "Col23", "Col23", "Col24", "Col24",
"Col26", "Col26", "Col26", "Col27", "Col22", "Col23", "Col24",
"Col22", "Col22", "Col22", "Col22", "Col22", "Col23", "Col23",
"Col23", "Col24", "Col25", "Col26", "Col26", "Col27", "Col27",
"Col27", "Col27", "Col27", "Col28", "Col28"), Exist_ = c("Sim",
"Sim", "Sim", "Sim", "Sim", "Sim", "Sim", "Sim", "Sim", "Sim",
"Sim", "Sim", "Sim", "Sim", "Sim", "Sim", "Sim", "Sim", "Sim",
"Sim", "Sim", "Sim", "Sim", "Sim", "Sim", "Sim", "Sim", "Sim",
"Sim", "Sim", "Sim", "Sim", "Sim", "Sim", "Sim", "Sim", "Sim",
"Sim", "Sim", "Sim", "Sim", "Sim", "Sim", "Sim", "Sim", "Sim",
"Sim", "Sim", "Sim", "Sim", "Sim", "Sim", "Sim", "Sim", "Sim",
"Sim", "Sim", "Sim", "Sim", "Sim"), contar = c(1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), total = 1:60), class = "data.frame",
row.names = c(NA,
-60L), .Names = c("Col2", "T_Ef", "Exist_", "contar", "total"
))
and
dput(newdf2)
structure(list(Col2 = c(2013L, 2013L, 2013L, 2013L, 2013L, 2013L,
2013L, 2013L, 2013L, 2013L, 2013L, 2015L, 2016L, 2016L, 2017L,
2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L, 2017L
), T_IP = c("Col11", "Col11", "Col12", "Col12", "Col13", "Col13",
"Col13", "Col14", "Col15", "Col15", "Col15", "Col12", "Col12",
"Col12", "Col11", "Col11", "Col11", "Col11", "Col12", "Col12",
"Col13", "Col14", "Col14", "Col15"), Ex_IP = c("Sim", "Sim",
"Sim", "Sim", "Sim", "Sim", "Sim", "Sim", "Sim", "Sim", "Sim",
"Sim", "Sim", "Sim", "Sim", "Sim", "Sim", "Sim", "Sim", "Sim",
"Sim", "Sim", "Sim", "Sim"), Qt = c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L), total_2 = 1:24), class = "data.frame", row.names = c(NA,
-24L), .Names = c("Col2", "T_IP", "Ex_IP", "Qt", "total_2"))
The labels I've created are as follows:
dput(Label_ef)
c("Ef1", "Ef2", "Ef3", "Ef4", "Ef5", "Ef6", "Ef7")
dput(IPs)
c("OP", "Conselhos", "Conferências", "Mov. Sociais", "Outros")
The question would be: how could I fix subtitle overlays?
Here are the codes I used and the generated image. Thanks!
dt_plot = ggplot() +
geom_jitter(data= newdf, aes(x=Col2, y=total, fill=T_Ef),
shape=21, size=4, alpha=0.2) +
scale_fill_discrete(labels= Label_ef) +
geom_jitter(data=newdf2, aes(x=Col2, y=total_2, fill=T_IP),
shape=24, size=3, alpha=0.5) +
scale_fill_discrete(labels=IPs) +
theme_classic()