Hello Rstudio community,
I would like to make 2 breaks of x axis on my graphic with the package ggbreak and function scale_x_break.
I have some problems to define well my parameters and arguments.
I would like to :
-remove the X axis on the top of my graphic,
-remove the background of my graph ( transparent background),
-have the same width of my error bar on all my graphics section ( there are a problems and some error bar are more important than others),
-keep the same space/scale between all labels on my X axis ( regular space on all axis ),
- add parrallel bar for significate the axis break.
I join the code , the expected graphic (with in red the customize suggestion on graph)
Thank you for your help :).
my code :
library("ggplot2")
library("scales")
library("grid")
library("reshape2")
library("ggbreak")
setwd("name of the route")
df <- data.frame(Temps_jour = 1:20,Cond=c("BH", "H"), SE= c(rnorm(0.1) + 0.015, rnorm(0.23) + 0.011, rnorm(0.51) + 0.0001, rnorm(1) + 0.61),
Conc = c(rnorm(5) + 4, rnorm(5) + 20, rnorm(5) + 5, rnorm(5) + 22)
)
head(df) #verifie le formatage du fichier
df$cond <- factor(df$Cond, levels = c("BH","H"))
palette=c("#ff6633","#006600")
p1<-ggplot(df, aes(x=Temps_jour, y=Conc, color= cond))+
theme_void()+
scale_colour_manual(values=palette)+
geom_point(size=.5, aes(colour = cond)) +
geom_line(size=.5, aes(colour = cond, group= cond))+
theme(aspect.ratio = 2 / 3,
axis.line = element_line(colour = "black"),
axis.text.y=element_text(face="plain", colour = "black", size=11, family="Times New Roman"),
axis.text.x=element_text(face= "plain", colour = "black", size=11, family="Times New Roman"),
axis.ticks = element_line(colour="black", size= 0.3),
axis.ticks.length = unit(0.15, "cm"),
panel.spacing = unit(4, "lines"),
strip.background = element_blank(),
strip.text.x = element_blank(),
legend.text=element_text(size=12))
p<- p1+ scale_y_continuous(limits = c(0, 25),expand = c(0, 0), breaks = seq (0, 30, by= 2))+
scale_x_continuous(expand = c(0, 0), breaks = seq (0,20, by= 1)) +
scale_x_break(expand = F, breaks=c(3, 6),scale= 1, space = 0.5, ticklabels =c(3,4,5,6,7,8,9,10))+
scale_x_break(expand = F, breaks=c(10.1,14 ),scale= 1, space = 0.5, ticklabels =c(15,16,17,18,19,20))+
geom_errorbar(aes(ymin=Conc-df$SE, ymax=Conc+df$SE), width=0.5,position=position_dodge(0.05))
ggsave(filename = "test.png",
plot = p,
bg = "transparent",
width = 8, height = 5, units = "in")