I'm trying to plot a graph using ggplot2 builder. My graph has species (Sp.) for X and percentage (Cover) for Y, with Gradient as groups and Sites as facet. However, my graph is giving me a value of 400 on the Y axis.
This is my df structure:
> data.frame': 720 obs. of 6 variables:
> Site : Factor w/ 2 levels "DRP","PSP": 2 2 2 2 2 2 2 2 2 2 ...
> Plot_ID : int 1 2 3 4 5 6 7 8 9 10 ...
> Gradient: Factor w/ 3 levels "Low","Medium",..: 3 3 3 3 3 3 3 3 3 3 ...
> Sp. : Factor w/ 4 levels "AG","FA","SN",..: 2 2 2 2 2 2 2 2 2 2 ...
> P.A : int 1 1 1 1 1 1 1 1 1 1 ...
> Cover : int 16 36 16 36 36 63 16 36 36 36 ...
This is my df table:
Site Plot_ID Gradient Sp. P.A Cover G2 Percentage
> 1 PSP 1 High FA 1 16 3 0.16
> 2 PSP 2 High FA 1 36 3 0.36
> 3 PSP 3 High FA 1 16 3 0.16
> 4 PSP 4 High FA 1 36 3 0.36
> 5 PSP 5 High FA 1 36 3 0.36
> 6 PSP 6 High FA 1 63 3 0.63
Sample of dataset:
Site Plot_ID Gradient Sp. P/A Cover
PSP 1 High FA 1 16
DRP 1 Medium FA 0 0
PSP 1 High AG 1 16
DRP 1 Medium AG 0 0
PSP 1 High SS 0 0
DRP 1 Medium SS 0 0
PSP 1 High SN 1 16
DRP 1 Medium SN 0 0
PSP 2 High FA 1 36
DRP 2 Medium FA 0 0
PSP 2 High AG 0 0
DRP 2 Medium AG 1 3
PSP 2 High SS 0 0
DRP 2 Medium SS 0 0
PSP 2 High SN 0 0
DRP 2 Medium SN 0 0
PSP 3 High FA 1 16
DRP 3 High FA 1 1
PSP 3 High AG 1 16
DRP 3 High AG 1 36
PSP 3 High SS 0 0
DRP 3 High SS 0 0
PSP 3 High SN 0 0
DRP 3 High SN 0 0
PSP 4 High FA 1 36
DRP 4 High FA 1 16
PSP 4 High AG 0 0
DRP 4 High AG 1 1
PSP 4 High SS 0 0
DRP 4 High SS 1 16
PSP 4 High SN 0 0
DRP 4 High SN 1 16
PSP 5 High FA 1 36
DRP 5 Medium FA 0 0
PSP 5 High AG 0 0
DRP 5 Medium AG 0 0
PSP 5 High SS 0 0
DRP 5 Medium SS 0 0
PSP 5 High SN 0 0
This is the code ggplot gave me:
ggplot(df) +
aes(
x = Sp.,
fill = Gradient,
group = Gradient,
weight = Cover
) +
geom_bar(position = "dodge") +
scale_fill_brewer(palette = "Greys", direction = 1) +
theme_bw() +
facet_wrap(vars(Site))
This is the result graph. As you can see Y axis is showing 400, but my highest % cover is 63%.
It doesn't make sense to me to have 400 for Y. As can be seen in the table header I try to divide the % cover by 100 (as was suggested in a different post), but the only thing that changed was that instead of 400 the Y axis higher level was 4.
I'd also like to have error bars in the graph.
I think you want something like this, where you are plotting the mean +- CI for each category.