Change the order of discrete axis Generate a… Change the order of discrete axis. Generate a factor with reversed levels or use a new ggplot2 option.


df$X1 = with(df, factor(X1, levels = rev(levels(X1))))

  1. Reverse the order of a discrete-valued axis
  2. Get the levels of the factor
flevels <- levels(PlantGrowth$group)
  1. "ctrl" "trt1" "trt2"
  2. Reverse the order
flevels <- rev(flevels)
  1. "trt2" "trt1" "ctrl"
bp + scale_x_discrete(limits=flevels)

Leave a Reply

Your email address will not be published. Required fields are marked *