3
I would like a help to solve this problem. I would like the caption to present dotted lines (linetype
), dotted (shape
) and colors (colour
) equal to the graph, but this graph has a double axis for y, so I had to add the separate lines, because there is a transformation, to be on the same plotting scale.
In the figure it is possible to observe that the legend displays only 1 type of shape
.
library(ggplot2)
library(lubridate)
clima<-structure(list(data=structure(c(15489,15490,15491,15492,
15493,15494,15495,15496,15497),class="Date"),VV=c(1.63,
2.87,2.33,2.33,2.43,0,3.07,4.47,4.47),Tmax=c(29.63,
30.63,30.77,29.97,29.65,30.1,31.13,31.53,31.3),Tmin=c(19.6,
15.32,15.38,14.98,14.8,15.05,15.57,15.77,15.65),Tmed=c(24.62,
22.98,23.08,22.48,20.9,22.58,23.35,23.65,23.48),UR=c(79.8,
74.6,73.3,79.3,77.6,72.9,70.5,70.4,72.8),Ubu=c(54.72,
46.31,42.61,35.19,29.59,27.15,23.05,16.77,11.97),P=c(0L,
0L,0L,0L,0L,0L,0L,0L,0L)),row.names=c(NA,-9L),class="data.frame")
clima$data<-ymd(clima$data)
coef<-10
ggplot(clima,aes(x=data))+
geom_line(aes(y=VV,colour="V. Vento"),size=1,linetype=2)+
geom_point(aes(y=VV,colour="V. Vento"),shape=15,size=3)+
geom_line(aes(y=UR/coef,colour="UR ar"),linetype=1,size=1)+
geom_point(aes(y=UR/coef,colour="UR ar"),shape=16,size=3)+
scale_y_continuous(name = expression("Velocidade do Vento (m s"^2*")"),sec.axis = sec_axis(~ . *coef,name=expression("Umidade relativa do ar (%)")))+
scale_x_date("",date_labels ="%d/%m")+
scale_colour_manual("",breaks=c("V. Vento","UR ar"),values = c("blue","black"))+
#scale_shape_manual("",values=c(15,16))+
#scale_linetype_manual("",values=c(2,1))+
theme(
panel.background = element_rect(fill=NA),
panel.border = element_rect(fill=NA),
axis.title.y = element_text(size = rel(1.5), angle = 90),
legend.text = element_text(size=12,face = "bold"),
axis.text = element_text(size=12,face="bold"),
legend.position = "bottom")
The column
coef
is not part of the data frameclima
.– Marcus Nunes
actually it’s just a data for transformation, I guess I forgot to put :/.
– Jean Karlos