Reputation: 23
I need to make a complex barplot and I'd like to have two different variables show up in each of my facetted boxes. Currently I can get the colors
The top 12 rows of my data looks like this:
> alldata[1:12,]
value layer Resolution Season Variable
1: 1.487185e+01 b.01K 1km base ET
2: 2.280336e+01 b.01K 1km peak ET
3: 3.252913e+01 b.01K 1km summer ET
4: 2.379603e+07 b.01K 1km base Q
5: 4.068850e+07 b.01K 1km peak Q
6: 2.265410e+07 b.01K 1km summer Q
7: -2.626421e+07 b.01K 1km base deltaS
8: 2.541856e+07 b.01K 1km peak deltaS
9: 2.729352e+06 b.01K 1km summer deltaS
10: 6.137754e+02 b.01K 100m base ET
11: 1.452516e+03 b.01K 100m peak ET
12: 2.218111e+03 b.01K 100m summer ET
My code looks like this:
melt=melt(alldata,id=c("layer","Resolution","Season","Variable"),measure=c("value"))
print(ggplot(data=melt,aes(x=Season,y=value))
+geom_bar(stat="identity",position="dodge",aes(fill=Variable))
+facet_wrap(~ layer)
)
And my plot looks like this (ignore the missing "ET" variable):
I've got my facets, x-axis groups, and colors how I need, but I cannot find a way to create two different types of bars. For each of my 'id' columns I'd like the following visuals:
layer- facet row
scaling factor- facet column
bargroup- season
color- variable
??BARTYPE?? (i.e. one filled and one open, or slashed lines, or anything)- resolution
Does anyone know how to create different bartypes (in a line plot I could have dotted lines and regular lines, with the color corresponding to a different variable).
Thank you!
Upvotes: 0
Views: 994
Reputation: 35392
You can use alpha
, with some altered data since you didn't share enough:
ggplot(data=melt,aes(x=Season,y=value,fill=Variable,alpha=Resolution)) +
geom_col(position="dodge", col=1)
Add e.g. scale_alpha_manual(values = c(0.4, 1))
to make the lighter bars more solid.
Upvotes: 1