R 用负值和正值更改条数(ggplot)的位置
我有下一个代码,我有负的正值和负值,我想把正值放在条的边缘上面,负值放在条的边缘下面。我也想知道如何改变y轴(限制),改变“Flujo”的顺序,以及如何改变背景图R 用负值和正值更改条数(ggplot)的位置,r,ggplot2,R,Ggplot2,我有下一个代码,我有负的正值和负值,我想把正值放在条的边缘上面,负值放在条的边缘下面。我也想知道如何改变y轴(限制),改变“Flujo”的顺序,以及如何改变背景图 tabla <- Flujo Mes Valor 1 Qns Septiembre 79.4 2 Qnl Septiembre -97.5 3 Qh Septiembre -3.1 4 Qe Septiembre -11.3 5 Qr Septiembre
tabla <-
Flujo Mes Valor
1 Qns Septiembre 79.4
2 Qnl Septiembre -97.5
3 Qh Septiembre -3.1
4 Qe Septiembre -11.3
5 Qr Septiembre 0.5
6 Qg Septiembre 16.5
7 Qm Septiembre 15.5
8 Qns Octubre 79.1
9 Qnl Octubre -87.8
10 Qh Octubre -0.8
11 Qe Octubre -1.7
12 Qr Octubre 0.0
13 Qg Octubre 36.0
14 Qm Octubre -57.9
tabla<-data.frame("Flujo"=c("Qns","Qnl","Qh","Qe","Qr","Qg","Qm","Qns","Qnl","Qh","Qe","Qr","Qg","Qm"),
"Mes"= rbind(array(" Septiembre", dim=c(7,1)) , array("Octubre", dim=c(7,1))) ,
"Valor"=round(c(s1$Qns,s1$Qnl,s1$Qh,s1$Qe,s1$Qr,s1$Qg,s1$Qm,s2$Qns,s2$Qnl,s2$Qh,s2$Qe,s2$Qr,s2$Qg,s2$Qm),digits=1))
colors <-c("Qns"="red","Qnl"="blue","Qh"="deeppink","Qe"="darkgoldenrod1","Qr"="darkblue","Qg"="green","Qm"="brown")
fig31 <- ggplot(data=tabla, aes(x=Mes, y=Valor,fill=Flujo)) +
geom_bar(stat="identity", color="black", position=position_dodge())+
theme_minimal()+
geom_text(aes(label=Valor),position=position_dodge(width=0.9),size=4, vjust=1.5)+
scale_fill_manual(values = colors) +
theme_light()
fig31
tabla这里有一种方法可以做到:我用geom\u col
更改了geom\u bar
,并在geom\u text()中放入ifelse。在这里,您可以定义数字的位置
0、-1,1.5`
fig31 <- ggplot(tabla, aes(Mes, Valor, fill=Flujo)) +
geom_col(position = position_dodge()) +
geom_text(aes(label = paste(Valor)),
position=position_dodge(width=0.9),size=3,
vjust = ifelse(tabla$Valor >= 0, -1, 1.5)) +
scale_fill_manual(values = colors) +
theme_light()
fig31
fig31=0,-1,1.5))+
比例\填充\手动(值=颜色)+
主题灯()
图31
非常感谢您!