简体   繁体   中英

R boxplot ggplot issues

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 experiments in data is a factor. If you run str(data) , I imagine that experiments is 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

data$experiments <- as.character(data$experiments)

Or remove the unused level in the factor

data$experiments <- droplevels(data$experiment)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM