I have a data set with columns of date, location, concentration, species, species count. For example...
date location concentration species count
6-4 A 0.5 shark 4
6-4 A 0.5 turtle 6
6-4 B 0.7 shark 4
6-4 B 0.7 turtle 2
6-4 B 0.7 ray 5
6-5 A 1.8 shark 6
6-5 A 1.8 ray 2
6-5 A 1.8 turtle 4
6-5 A 1.8 barracuda 3
6-5 B 1.5 shark 9
6-5 B 1.5 ray 1
6-5 B 1.5 turtle 3
I am trying to make a plot with two y-axis (1 for count, 1 for concentration) and the x-axis is as.factor(date). I want a stacked-bar plot for the species counts with color associated to each species, a line that shows the changing concentration, and facet_wrap( ~ location)
I have made this plot without having stacked bars, as the bars represent the total count of all species combined. Combining all species counts to one value allows for there to only be one observation per date at each location with one value of concentration, which is why the line code works.
The problem with making the stacked bar plot is that concentration has repeat observations of the same value. All the other plotting code works for setting up the two axis and scales, plotting the stacked bars, but the line will not plot.
Any tips for dealing with this issue? Thank you in advance!