df1 <- data.frame(level=c("1","2","3"), MeP=c("18.94","21.14","24.25"), seP=c("5.41","5.36","5.38") MeI=c("9.16","10.04","12.15") seI=c("2.92","2.90","2.91")
df1 <- data.frame(level = c(1, 2, 3),
MeP = c(18.94, 21.14, 24.25),
seP = c(5.41, 5.36, 5.38),
MeI = c(9.16, 10.04, 12.15),
seI = c(2.92, 2.90, 2.91))
Y estoy usando este código para graficar
scaleFactor <- max(df1$MeI) / max(df1$MeP)
ggplot(df1, aes(x=level, width=.4)) +
geom_col(aes(y=MeI), fill="blue",position=position_nudge(x=-.4))+ geom_errorbar(aes(ymin = MeI-seI, ymax = MeI+seI), stat = "identity" ,width = 0.15, size=0.8, position=position_dodge())+
geom_col(aes(y=MeP*scaleFactor), fill="red")+
scale_y_continuous(name="MeI", sec.axis = sec_axis(~./scaleFactor, name="MeP")) geom_errorbar(aes(ymin = MeP-seP, ymax = MeP+seP), stat = "identity", width = 0.15, size=0.8, position=position_nudge(x=-0.05))
scaleFactor <- max(df1$MeI) / max(df1$MeP)
library(ggplot2)
ggplot(df1, aes(x = level, width = 0.4)) +
geom_col(aes(y = MeI), fill = "blue",
position = position_nudge(x = -0.4)) +
geom_errorbar(aes(ymin = MeI-seI, ymax = MeI+seI),
stat = "identity",
width = 0.15,
size=0.8,
position = position_dodge()) +
geom_col(aes(y = MeP*scaleFactor), fill="red") +
scale_y_continuous(name = "MeI",
sec.axis = sec_axis(~./scaleFactor, name="MeP")) +
geom_errorbar(aes(ymin = MeP-seP, ymax = MeP+seP),
stat = "identity",
width = 0.15,
size = 0.8,
position = position_nudge(x = -0.05))
Cómo debo hacer para que las barras de error aparezcan donde le corresponden?
Qué debo hacer para que se vean completas? Pensé
Pensé que con position=position_dodge()position=position_dodge()
funcionaría pero veo que no.
Por último, cómo puedo ajustar el color usando la paleta RColorBrewer? intenté
Intenté poninedo scale_fill_brewer(palette="Set2")scale_fill_brewer(palette="Set2")
en el código pero asignó un color a cada barra, sino que puso todo en gris.