I am using ggplot and have created a geom_bar plot with the command fill=factor(Zone) in order to show 3 bars (Zone a,b,c) for each trial (trial 1, 2) on the x axis.
However, this also automatically assigns colours to my bars based on the 'Zone' (i.e. Zone a=red, b=blue, c=green) and not my manual Palette.
How do i keep the x-axis seperated by trial and zone (i.e. exactly as it is), but assign the bar colours manually or according to another parameter?
data:
dput(summarydata)
structure(list(trial = c(1, 1, 1, 2, 2, 2), zone = c("c", "b",
"a", "c", "b", "a"), N = c(77, 77, 77, 9, 9, 9), mean = c(24.339207007839,
24.3293834745274, 51.3314095176336, 4.97411297139253, 61.7131442273329,
33.3127428012746), median = c(24.2125207231389, 24.9084249084249,
50.7692307692308, 5.20833333333333, 67.6056338028169, 30.2083333333333
), sd = c(9.57972648488188, 10.5885530988102, 17.117966513353,
2.96053414557149, 12.2967321565455, 12.5049588941075), se = c(1.0917111525428,
1.20667761501389, 1.95077333167849, 0.986844715190498, 4.09891071884851,
4.16831963136916)), .Names = c("trial", "zone", "N", "mean",
"median", "sd", "se"), row.names = c(NA, -6L), class = "data.frame")
Code:
Palette1<-c("red", "red", "blue", "red", "green", "blue")
ggplot(summarydata, aes(x=trial, y=mean, fill=zone))+
geom_bar(position="dodge",stat="identity") +
scale_x_discrete (labels=c ("Trial 1", "Trial 2"))+
scale_fill_manual (values=Palette1)
+
for thescale_fill_manual
to be taken into account. – Haboryme