7

I have data on the catch rate of certain species of fish.

fish 1  fish 2  fish 3
0.000   3.265   9.872
2.147   1.013   0.000

I have calculated the mean catch rate for each fish using:

a <- colMeans(df)

I have also calculated the standard error:

stdError <- (sapply(df,sd))/sqrt(length(df))

I have created a dotplot using:

dotplot(a, xlab="mean catch", ylab = "species",las =2,)

How do I add error bars to this plot? I would prefer not to use ggplot if possible. I am currently using the inbuilt functions in R but have access to Lattice.

Sorry for what is probably a basic question, I am entirely new to plots in R.

0

1 Answer 1

7

dotplot is a lattice function and most default lattice functions don't have great support for confidence intervals. The Hmisc package extends most lattice functions to better incorporate confidence intervals.

Here's an example of how you would use it. Note that we combine the data you want to plot here into a data.frame so we can use a proper formula symtax

mm<-data.frame(a,stdError, fish=names(a))

library(lattice)
library(Hmisc)
Dotplot(fish~Cbind(a, a-stdError, a+stdError), mm, 
    xlab="mean catch", ylab = "species",las =2)

and this produces

enter image description here

Note that the Hmisc version of the function is called Dotplot while the lattice version is called dotplot; capitalization matters.

Here I've just added/subtracted one standard error from the mean. You can calculate the confidence intervals however you like.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.