Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 208690

using ggplot to add error bars to Barplot

$
0
0

I am drawing a bar plot of means for a diversity index for a study i have done. I have calculated the index for each sample and added it to my table (which i orignally read in). I then calculated the index means for two different environments and plotted those means. However, i cannot work out how to add error bars.i understand ggplot2 is a useful tool for doing this, but cannot get my head around the explanation.

SO, basically trying to take the means of two values from a table, and plot a bargraph with error bars. this is my code at the moment

mean Shannon of river and lake

`mean_river <- mean(parasite_data$Shannon.index[1:24])
mean_lake <- mean(parasite_data$Shannon.index[25:43])`

matrix of means #

Shannon_mean <- matrix(c(mean_river, mean_lake), nrow = 1, ncol = 2, dimnames = list(c("mean"), c("River","Lake")))

plot graph #

`barplot(Shannon_mean, 

# name axis 
    xlab = "Environment", ylab = "Shannon Diversity Index", 

# title of graph 
    main = "Diversity of Parasites found on Fish from River 
            and Lake Environments", 

# size of title text and colour of bars #
    cex.main = 1, col = "gray80")`

like i said, i have attempted to use ggplot, but cannot read the data in correctly. any help would be appreciated.


Viewing all articles
Browse latest Browse all 208690

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>