Plotting individual points with error terms onto a ggplot

Hello,

This is my second only time using R, so apologies if this seems like a simple question.

I have created some box whisker plots using the code below to summarise the Rugosity data from some samples of different coral species.
Each species also has an index value with a +- error term. Is there a way to create a second Y-axis, then mark each index value with its error term on the box-whisker plot for the respective coral species?

I have tried various second/dup axis options, but each time I seem to lose my original axis. Additionally, I would like the index points+-error terms to be individual points, as opposed to joined up as part of a line graph etc.

I know you can add individual reference lines onto such charts, but Ideally, I am looking for a stand alone marker with an error bar.

Any help to find a solution to this would be greatly appreciated. Thanks

data.frame(
    Rugosity = c(2.310344828,2.25,1.958333333,1.071428571,
                 1.230769231,1.153846154,1.444444444,1.625,1.714285714,
                 1.5,1.666666667,1.851851852,1.517241379,3.117647059,
                 3.642857143,3.4,3.375),
       Index = c(3,3,3,2.4,2.4,2.4,2.4,2.2,2.2,2.2,
                 2.5,2.5,2.5,2.1,2.1,2.1,2.1),
       Error = c(0.28,0.28,0.28,0.12,0.12,0.12,0.12,
                 0.11,0.11,0.11,0.24,0.24,0.24,0.08,0.08,0.08,0.08),
    Fullname = as.factor(c("Acropora branching",
                           "Acropora branching","Acropora branching",
                           "Acanthastrea encrusting","Acanthastrea encrusting",
                           "Acanthastrea encrusting","Acanthastrea encrusting","Favia",
                           "Favia","Favia","encrusting","encrusting",
                           "encrusting","massive","massive","massive","massive")),
        Type = as.factor(c("genera","genera",
                           "genera","genera","genera","genera","genera",
                           "genera","genera","genera","morphotype","morphotype",
                           "morphotype","morphotype","morphotype","morphotype",
                           "morphotype"))
)
#>    Rugosity Index Error                Fullname       Type
#> 1  2.310345   3.0  0.28      Acropora branching     genera
#> 2  2.250000   3.0  0.28      Acropora branching     genera
#> 3  1.958333   3.0  0.28      Acropora branching     genera
#> 4  1.071429   2.4  0.12 Acanthastrea encrusting     genera
#> 5  1.230769   2.4  0.12 Acanthastrea encrusting     genera
#> 6  1.153846   2.4  0.12 Acanthastrea encrusting     genera
#> 7  1.444444   2.4  0.12 Acanthastrea encrusting     genera
#> 8  1.625000   2.2  0.11                   Favia     genera
#> 9  1.714286   2.2  0.11                   Favia     genera
#> 10 1.500000   2.2  0.11                   Favia     genera
#> 11 1.666667   2.5  0.24              encrusting morphotype
#> 12 1.851852   2.5  0.24              encrusting morphotype
#> 13 1.517241   2.5  0.24              encrusting morphotype
#> 14 3.117647   2.1  0.08                 massive morphotype
#> 15 3.642857   2.1  0.08                 massive morphotype
#> 16 3.400000   2.1  0.08                 massive morphotype
#> 17 3.375000   2.1  0.08                 massive morphotype

library(ggplot2)
library(dplyr)

data.frame <- data.frame %>% mutate(BothLabels = reorder(Type, Rugosity))
#> Error in UseMethod("mutate_"): no applicable method for 'mutate_' applied to an object of class "function"

RmType <- function(string) {
  sub(".+_", "", string)}

p <- ggplot(data.frame, aes(y=Rugosity, x=reorder(Fullname, Rugosity, fun=mean))) + geom_boxplot()
p +guides()+ facet_grid(~Type)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.