Reputation: 283
I am trying to make a box plot without faceting. Data look like this:
species elevation hbl
datae 400 83
datae 300 92
datae 257 92
datae 350 102
datae 500 89
datae 625 100
datae 625 94
datae 632 87
datae 1000 100
datae 940 89
datae 1050 98
datae 550 79
datae 700 102
datae 638 86
abrae 1500 71
abrae 1600 80
abrae 1405 80
abrae 1470 90
abrae 1000 77
abrae 1125 88
abrae 1125 82
abrae 1132 75
abrae 1500 88
abrae 1440 77
abrae 1550 86
abrae 1050 67
abrae 1200 90
abrae 1138 74
abrae 1000 83
abrae 1100 92
abrae 905 92
abrae 970 102
abrae 500 89
abrae 625 100
abrae 625 94
abrae 632 87
abrae 1000 100
abrae 940 89
abrae 1050 98
mingan 1000 120
The code below produces a box plot that pools hbl values for the two species of interest when both are present in a single bin of elevation, giving red (abrae), blue (datae), and grey (both), but I would like to get separate boxes for each species in all bins, on the same plot. What am I missing?
library(ggplot2)
d = read.csv("path_to_file")
p = ggplot(d[d$species=="abrae" | d$species=="datae",], aes(x=elevation, y=hbl, fill=species, group=cut_interval(x=elevation, length=200)))
p + geom_boxplot()
Upvotes: 2
Views: 5332
Reputation: 1677
ggplot(d[d$species=="abrae" | d$species=="datae",], aes(x=cut_interval(x=elevation, length=200), y=hbl, fill=species)) + geom_boxplot()
Upvotes: 3