1

I have a question about how I can do a scatterplot with error bars. I´m working with stable isotopes so I have data on D13C and D15N for faunal samples. I want to obtain a plot like this one (without convex hulls) attached (target)target.png

But on the contrary I obtain a plot like this (CNPlot)CNPlot.png I´m using this script :

a<-read.table("Means.txt", header = TRUE)
theme_set(theme_classic(base_size = 16))
ggplot(a, aes(x=D13C, y=D15N)) +
geom_errorbar(aes(ymax=D13C+D13C.ds, ymin=D13C-D13C.ds), width=0.15,alpha=.8)+
geom_errorbarh(aes(xmax=D15N+D15N.ds, xmin=D15N-D15N.ds), height=0.15,alpha=.8)+  
  geom_point(aes(shape=Species),fill="white",size=4) +
  geom_point(aes(color=Species,fill=Species,shape=Species),size=4, alpha = .5) +
  scale_color_manual(values=c("black","dodgerblue1","coral4","darkorchid"))+
  scale_fill_manual(values=c("black","dodgerblue1","coral4","darkorchid"))+
  scale_shape_manual(values=c(21,23,22,24))+
 labs(title=NULL,
       subtitle=NULL,
       caption=NULL,
       x=expression(paste(delta^{13}, "Ccol(‰)")),      
       y=expression(paste(delta^{15}, "N(‰)")))

and I have two datasets but I´m using the one named Means but I have another one named CN_fauna where I included the raw data

Means:

Species    D13C    D13C.ds    D15N    D15N.ds
Bird    -16.4    7.1    7.6    1.5
SH    -18.5    1.7    5.5    2.7
CH    -14.8    2.9    8.8    0.6
Deer    -19.2    0.7    4.8    1.04

CN_fauna:

taxa    D13C    D15N
Bird    -24.1    7.9
Bird    -9.9    9
Bird    -15.2    5.9
SH    -17.0    9.6
SH    -16.6    7.3
SH    -20.3    4.6
SH    -20.3    2.6
SH    -20.3    2.7
SH    -18.6    6.6
CH    -16.9    9.4
CH    -11.5    8.2
CH    -16.1    8.8
Deer    -18.6    3.0
Deer    -19.1    6.0
Deer    -18.3    5.4
Deer    -17.9    5.4
Deer    -19.2    5.6
Deer    -20.4    5.6
Deer    -19.5    6.1
Deer    -20.3    5.9
Deer    -18.7    5.4
Deer    -19.7    3.8
Deer    -19.2    3.4
Deer    -19.9    4.1
Deer    -18.4    4.3
Deer    -20.1    4.1

I do not understand why the scales of the error barplots are different in my plot, any help is more than welcome.

stefan
  • 90,330
  • 6
  • 25
  • 51
  • Welcome to SO! While your question already is quite close to a MRE I would still suggest to have a look at how to provide [a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). In particular, if you want to post your data(sets), type `dput(NAME_OF_DATASET)` into the console and copy the output starting with `structure(....` into your post. Also, something went wrong when you added the image of your plot. – stefan Jul 19 '22 at 17:26

1 Answers1

0

Not to take away from the sage advice that @stefan provided (reproducible questions get better responses faster)...

I could be wrong, but I think your errorbar data is on the wrong axis. Is that what you were trying to create?

enter image description here

If so, you need to change your xmin to ymin and so on for the two errorbar layers. It would look something like this:

ggplot(Means, aes(x = D13C, y = D15N)) +
  geom_errorbar(aes(xmax = D13C + D13C.ds, 
                    xmin = D13C - D13C.ds), width=0.15,alpha=.8)+
  geom_errorbar(aes(ymax = D15N + D15N.ds, 
                    ymin = D15N - D15N.ds), height=0.15,alpha=.8)+  
  geom_point(aes(shape=Species),fill="white",size=4) +
  geom_point(aes(color=Species,fill=Species,shape=Species),size=4, alpha = .5) +
  scale_color_manual(values=c("black","dodgerblue1","coral4","darkorchid"))+
  scale_fill_manual(values=c("black","dodgerblue1","coral4","darkorchid"))+
  scale_shape_manual(values=c(21,23,22,24))+
  labs(title=NULL,
       subtitle=NULL,
       caption=NULL,
       x=expression(paste(delta^{13}, "Ccol(‰)")),      
       y=expression(paste(delta^{15}, "N(‰)")))
Kat
  • 15,669
  • 3
  • 18
  • 51
  • Dear stefan and Kat thank you very much for your help, suggestions, and clarifications. For future posts, I´ll follow in detail the guidelines. Regarding my example, yes, there was an error, the x and y axes were confused when calling the errorbar functions. Again thanks for your help. All best, Paolo – Paolo Fisichella Jul 20 '22 at 20:05