Scatterplot with error bars

188 views
Skip to first unread message

Pablo Fisichella

unread,
Jul 18, 2022, 11:39:37 AM7/18/22
to ggplot2
Dear all,

I´m new in the group and with R in general. 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

Mean:
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.

Thanks

all best,

Paolo




Ron Crump

unread,
Jul 20, 2022, 4:15:29 AM7/20/22
to Pablo Fisichella, ggplot2
Hi Pablo,


> I´m new in the group and with R in general. 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

It looks to me like you have your x and y axes confused when
calling the errorbar functions.

+geom_errorbar(aes(ymax=D15N+D15N.ds,ymin=D15N-D15N.ds))
+geom_errorbarh(aes(xmax=D13C+D13C.ds,xmin=D13C-D13C.ds))

should be better.

You might get more help, and quicker, by using the rstudio
community (https://community.rstudio.com) as there isn't much traffic
on this list these days.

Hope this is helpful,
Ron.

Reply all
Reply to author
Forward
0 new messages