I am new in R and am trying to so some graphics using ggplot and a bit of reverse engineering. I have a data frame as:
> data
experiments percentages
1 A 72.11538
2 A 90.62500
3 A 91.52542
4 B 94.81132
5 B 96.95122
6 B 98.95833
7 C 83.75000
8 C 84.84848
9 C 91.12903
because A and B are similar experiments I do the following
data$experiments[data$experiments == "B"] = "A"
If I do now
ggplot(data, aes(x = experiments, y = percentages)) + geom_boxplot()
I get one box for A, one for C but still I get a label for B!
Is there any way of getting rid of B on the X axis?
Thanks a lot for your help
I’m guessing that
experimentsindatais a factor. If you runstr(data), I imagine thatexperimentsis a factor with 3 levels: A, B, and C. By default, strings are turned into factors when a data frame is created.The idea of factors is that they represent a set of possible values, even if not all the possibilities are in the actual data. There are two ways to fix this.
Convert the column to a string
Or remove the unused level in the factor