简体   繁体   中英

How to change the x-axis ticks on ggboxplot?

I have a ggboxplot that looks like this:

ggboxplot

I would like to change the x-axis ticks for the box plots to read "Uncontrolled Disease" and "Controlled Disease" instead of "Progressive" and "Stable". I've tried to use scale_x_discrete:

ggboxplot(inf, x = "DiseaseStatus", y = "log.IL-1RA", 
          color = "DiseaseStatus", palette = c("#00AFBB", "#E7B800"),
          ylim = c(-2,8),
          order = c("Progressive", "Stable"),
          scale_x_discrete(labels = c("Uncontrolled Disease", "Controlled Disease")),
          main = "IL-1RA",
          ylab = "log lab value", xlab = "DiseaseStatus")

But I get this error:

Error in !is.null(facet.by) | combine : 
  operations are possible only for numeric, logical or complex types

What am I doing wrong? Is it possible to change the x-axis ticks?

This should do the trick!

ggboxplot(inf, x = "DiseaseStatus", y = "log.IL-1RA", 
          color = "DiseaseStatus", palette = c("#00AFBB", "#E7B800"),
          ylim = c(-2,8),
          order = c("Progressive", "Stable"),
          main = "IL-1RA",
          ylab = "log lab value", xlab = "DiseaseStatus") +
          scale_x_discrete(labels = c("Uncontrolled Disease", "Controlled Disease"))

I used test data becuase I didnt have your data. This is the code I used

library(ggpubr)
data("ToothGrowth")
df <- ToothGrowth


ggboxplot(df, x = "dose", y = "len", width = 0.8) +
scale_x_discrete(labels = c("Uncontrolled Disease", "Controlled Disease", "third variable"))
              

测试数据箱线图

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